Are Django form widgets like datepicker and tabindex being snubbed?

I have been working on creating a stylish form and managed to find some interesting CSS to enhance it. The form is looking good, however, a couple of fields are not displaying correctly; particularly one that is associated with a choice field as the model has a foreign key, and another field that is a date field. I tried troubleshooting on Stack Overflow by using widgets, but it seems like my code is not functioning correctly, and there are no errors showing up in the developer's console. Below is my code:

from django import forms
from .models import Group

class GroupForm(forms.ModelForm):
    notes=forms.CharField(widget = forms.Textarea)
    billing_address = forms.ModelChoiceField(queryset = '', widget=forms.Select(attrs={'tabindex':'5'}))
    start_date = forms.DateField(widget=forms.TextInput(attrs=
                                {
                                    'class':'datepicker',
                                    'tabindex' : '6',
                                    'placeholder' : 'Groups start date'
                                }))

    class Meta:
        model=Group
        exclude = ['created_at', 'updated_at']

My template view consists of the following:

<div class="col-2">
    {{ form.billing_address.errors }}
    <label>
    Billing Address
        {{ form.billing_address }}
    </label>
    </div>
    <div class="col-2">
     {{ form.mailing_address.errors }}
    <label>
    Mailing Address
        {{ form.mailing_address }}
    </label>
  </div>
  <div class="col-4">
    <label>
      Start Date
     {{ form.start_date }}      
    </label>
  </div>

I have included all the necessary CSS and JS files in my base.html template:

    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<link href="{% static 'ipaswdb/css/styles.css' %}" type="text/css" media="all" rel="stylesheet">
<link href="{% static 'ipaswdb/css/switchery.min.css' %}" type="text/css" media="all" rel="stylesheet">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">

  <script type="text/javascript" src="{% static 'ipaswdb/js/switchery.min.js' %}"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
 <script type="text/javascript" src="{% static 'ipaswdb/js/bootstrap.min.js' %}"></script>

Despite following all the correct steps, the form is not rendering as expected. The source code that gets rendered is shown below:

   <label>
    Billing Address
        <select id="id_billing_address" name="billing_address">
<option value="" selected="selected">---------</option>
<option value="1">Las Cruces</option>
<option value="2">Albuquerque</option>
</select>
    </label>
    </div>
    <div class="col-2">

    <label>
    Mailing Address
        <select id="id_mailing_address" name="mailing_address">
<option value="" selected="selected">---------</option>
<option value="1">Las Cruces</option>
<option value="2">Albuquerque</option>
</select>
    </label>
  </div>
  <div class="col-4">
    <label>
      Start Date
     <input id="id_start_date" name="start_date" type="text" />     
    </label>
  </div>

Additionally, I have included my views.py file below, as I suspect there might be some discrepancies in the way I'm handling the forms:

class GroupCreateView(CreateView):
    model = Group

    fields = '__all__'
    exclude = ['created_at', 'updated_at']
    template_name = 'ipaswdb/group/group_form.html'

Here's my urls.py:

from django.conf.urls import url

from . import views
from ipaswdb.views import GroupCreateView

app_name = 'ipaswdb'
urlpatterns = [
    url(r'group/$', views.group_list, name='group_list'),
     url(r'group/(?P<group_id>[0-9]+)/$', views.group_detail, name='group_detail'),
    url(r'group/add/$', GroupCreateView.as_view(), name='group-add'), 

]

I'm not sure what I'm missing here. Despite following the correct procedures, it seems like something is not functioning as intended. Any insights would be greatly appreciated.
EDIT: I realized that the datepicker was not functioning due to the incorrect loading order of the jQuery UI JS file after jQuery, and the missing JavaScript to assign the datepicker class. This has been fixed subsequent to the form correction.

Answer №1

To implement the necessary changes, modify your view to utilize the following form:

from .forms import GroupForm

class GroupCreateView(CreateView):
    model = Group
    form_class = GroupForm
    ...

If you've omitted certain fields in the form, there is no need to include exclude in the view anymore.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to position a rectangle on top of a div that has been rendered using

I recently started using a waveform display/play library known as wavesurfer. Within the code snippet below, I have integrated two wavesurfer objects that are displayed and positioned inside div elements of type "container". My goal is to position my own ...

Having trouble with a parser error in jQuery ajax?

My code is giving me a parser error and failing. $.ajaxSetup({ type: 'GET', url: 'http://www.example.com/ajax', dataType: 'json' }); $('#addHotlink').click(function() { $('body').after('<d ...

The sequence of methods firing seems to be jumbled up

My attempt to utilize JSON for returning an array that can be manipulated later is encountering some issues when using AJAX to return a JSON encoded string. When debugging with alerts, it seems like the alerts are firing in the incorrect order. Check out ...

Tips for creating a plug-in plugin and applying the necessary parameters

(function( $ ){ var functions = { init : function( options ) { var settings = $.extend({ //Declaring default settings that can be overridden in the plugin call code: 7, listHe ...

Transferring information from an online platform onto pre-arranged sheets for hard copy

Has anyone had success printing from a website? I have some papers that are already printed with checkboxes. These checkboxes need to be filled in based on information entered through a web form or retrieved from a MySQL database. All of this information ...

"Encountering a Challenge with Setting Up Forms on

I've recently started learning to code and I'm facing an issue with my form appearing stretched out. You can view it here: I initially thought it was due to margins, so I increased them. Then, I tried adjusting the width to 50%, but that didn&ap ...

CSS: Adjusting the position of tooltips to align with the triggering element (rest of code is fully functional)

Looking to create a custom tooltip without relying on plugins. The goal is to align the tooltip vertically to the right of the triggering element, in this case, an input field. The current setup (see Fiddle demo) achieves the desired layout and content fo ...

Perform a single click and a double click on an anchor element in the document

I am attempting to implement two actions when a user clicks on an anchor tag. The anchor tag will contain a video link. My goal is for the URL to open in a new window when the user single-clicks on the anchor tag, and for the use of the HTML5 download attr ...

Try refreshing the webpage if the AJAX Update Panel experiences an issue

Currently, my website displays the status of multiple servers and provides information about user numbers in various systems. I have set up an AJAX UpdatePanel with an asp:Timer control to automatically refresh the data. Although this setup works smoothly ...

Tips on adjusting the size of a font icon using an inline element prior to the font being fully loaded

I'm facing an issue with embedding an icon font within text so that it wraps properly. Currently, the only way I can achieve this is by using &nbsp; between the text and the icon (i tag with font awesome). However, this causes a problem as the ico ...

Show both text and image inputs side by side within a table

Hey there, I'm trying to create a table with both text and image inputs inside. Here's the code I've attempted: <tbody> <tr> <td class="inputs"> <input type=" ...

Ensure child elements do not surpass parent size in HTML/CSS/Javascript without altering the children directly

I am intrigued by how iframes neatly encapsulate all site data within a frame and adjust it to fit the size. Is there any method to achieve this functionality in an HTML wrapper? Can the wrapper be configured so that regardless of the content, it is dis ...

Having Difficulty with Splicing Arrays in React?

Currently working on learning React and trying to develop my own mini-app. I'm basing it very closely on the project showcased in this video tutorial. I've run into an issue with the comment deletion functionality in my app. Despite searching va ...

Adjust the body class dynamically based on the URL in AngularJS

Here is the link to my website To Log In - http://localhost/ang/#/login To Access Dashboard - http://localhost/ang/#/dashboard See below for the HTML code for the body tag If the current URL is http://localhost/ang/#/login, then the body should include ...

Webpack2 now transforms sass/scss files into JavaScript rather than CSS during compilation

I've created a webpack script to compile all .scss files into one css file. I decided to use webpack instead of gulp or grunt for simplicity, as it can be configured in a single file. However, I am encountering an issue where scss files are being com ...

Tips for keeping images stationary while expanding on hover

Currently, I am in the process of developing my first website. My main goal is to create an image gallery that displays thumbnails of images and expands them when you hover over each one. Initially, I adjusted the sizes of the images to 100px*100px using H ...

Assign a class when a path is clicked using Leaflet.js

My goal is to apply a specific class to the clicked polygon by using the following code: function addClass() { function style(feature) { return { className: "active" }; } } function onEachFeature(feature, layer) { ...

Enhance Your Website with GatsbyJS Custom Scrollbars

I'm struggling to customize the default scrollbar on my Gatsby website with an overlay scrollbar. I want to avoid the page 'shifting' slightly to the left when switching between pages that have scrollbars and those that do not. My attempt i ...

What is the best way to transfer data between a checkbox/radiogroup and textview located in separate activities using Eclipse?

Is there a way to display a list of items on different pages with checkboxes and radio buttons that allow users to select items and calculate the total price dynamically? How can this be achieved? Below is the code snippet for the main page: package com. ...

Tips for displaying the webpage background above a specific div by utilizing a differently shaped div

I designed a webpage with a background image. At the top, I placed a div element (let's call it div_1) set to 50% width which creates a horizontal black bar with 60% opacity. Directly above that, towards the left at 50%, I want another div element (di ...