Questions tagged [django-widget]

Django widgets handle the rendering of the HTML for form fields

A widget is Django’s representation of a HTML input element. The widget handles the rendering of the HTML, and the extraction of data from a GET/POST dictionary that corresponds to the widget. -- https://docs.djangoproject.com/en/dev/ref/forms/widgets/

Django includes a number of built in widgets, including TextInput, RadioSelect and CheckboxInput. It is easy to change the way a form field is displayed by declaring the widget when you define your Django form.

For example, if you have a form ChoiceField, where the user can choose from a list of options, your choice of widget determines whether this is rendered as a dropdown menu, or a list of radio buttons.

If custom behavior is required, Django's built in widgets can be subclassed and extended.

329 questions
1
vote
1 answer

Django - Set different id for each radio button choice

I want to set different id for each radio choice. My Model:- class Preference(models.Model): BOARD_CHOICES = [('CB', 'CBSE'), ('IC', 'ICSE'), ('SB', 'State Board'), ('IB', 'International Board')] Board =…
1
vote
1 answer

Django Form (Checkbox) - unable to save data

I am trying to display a form (with multiple select checkbox) and save the data in database. But having some problem. Here is my model: class Preference(models.Model): CLASS_CHOICES = [('1', '1'), ('2', '2'), ('3', '3')] BOARD_CHOICES =…
1
vote
1 answer

Django MultiValueField

I'm struggling with some Django, where I want to make a custom MultiValueField combined with MultiWidget. I've read misc. tutorials, but it seem I'm missing something - most of them were quite old, which I suspect could be the reason. I'm using…
1
vote
1 answer

django form custom attrs widget imagefield

I have a model Prova: class Prova(models.Model): id = models.AutoField(primary_key=True) codice= models.TextField(blank=True, null=True) foto = models.ImageField(upload_to='stati/uploads/', blank=True) and this is the form: class…
summer
  • 213
  • 3
  • 12
1
vote
1 answer

Django admin date picker for search

I would like to use the Django date picker widget for searching in the admin. Lets suppose I have a model with field date_created. In the admin, I would like to have a date picker for date_created with start and end ranges using which I can filter…
Fahim Ahmed
  • 397
  • 4
  • 16
1
vote
0 answers

Django 1.10 single widget type for all ModelForm fields

I have a ModelForm, which is composed from Model, with huge amount of columns with very different data types. However, I need to make ModelForm whose all mentioned fields in ModelForm have the same widget type (for example, checkbox, but it may be…
Fusion
  • 5,046
  • 5
  • 42
  • 51
1
vote
2 answers

Using jQuery datepicker with multiple django forms in one page

So I have a create announcement form and then an edit form for each announcement and each form has its own datepicker. My function for controlling the datepicker is: $(function() { $( ".datepicker" ).datepicker({ changeMonth: true, …
Catherine
  • 241
  • 1
  • 2
  • 15
1
vote
1 answer

Correct way to implement django-widget-tweaks markup

I am trying to render a form using django-widget-tweaks to help with css and widget types. I performed the following steps: Install widget tweaks with pip3 in my venv successfully. Put 'widget_tweaks', in INSTALLED_APPS in settings.py. Put the…
Escher
  • 5,418
  • 12
  • 54
  • 101
1
vote
2 answers

How to change Django NullBooleanField widget application wide?

I would want to display all NullBooleanFields in my application as radio buttons. What's the best way to do it? Following template or something similar would be ideal. Just to allow rich styling and tone-of-voice different from plain…
fmalina
  • 6,120
  • 4
  • 37
  • 47
1
vote
1 answer

Django form field widget becomes hidden

Model field links as foreign_key to another model which has big amount of entries. I decided to replace default select for foreign_keys with simple link. And it works grate besides the fact that field becomes hidden! What should I do to avoid…
Alex T
  • 4,331
  • 3
  • 29
  • 47
1
vote
1 answer

How to pass parameters to widget js asset?

It is possible to pass custom js to a widget, as explained in the documentation. In my case, the custom js is this: function setUpImagePreview(inputId, imgId) { ... } window.onload = function() { // IDs hardcoded, VERY BAD! How to solve this? …
blueFast
  • 41,341
  • 63
  • 198
  • 344
1
vote
0 answers

What should be given to the render method of a ClearableFileInput?

I have a custom MultiWidget containing a ClearableFileInput widget. This MultiWidget manipulates small lists of strings (the list is encoded as a string in the database). Each of these string corresponds to a filename. In order to connect that…
Archimondain
  • 374
  • 2
  • 17
1
vote
1 answer

In Django how can I get a widget that accepts an ISO 8601 datetime string and works with a DateTimeField?

I want to submit an ISO 8601 datetime string with a time zone designator to a django form that I am writing. I want to use a standard DateTimeField for the datetime but have a widget that accepts such a datetime string. Is this possible, or am I…
BudgieInWA
  • 2,184
  • 1
  • 17
  • 31
1
vote
1 answer

Make django-leaflet widget in admin

Can I make django-leaflet widget in admin if my model: from django.contrib.gis.db import models as m from djgeojson.fields import GeometryCollectionField class Doc(m.Model): name = m.CharField() type = m.ForeignKey() geom =…
pirr
  • 445
  • 1
  • 8
  • 15
1
vote
1 answer

Django MultipleChoiceField restrictions on choices tuple

I am getting an error message when I try to use MultipleChoiceField with the CheckboxSelectMultiple widget. I built a form using Django's MultipleChoiceField that displays a set of checkboxes for the user to select: class…
kdubs
  • 936
  • 3
  • 22
  • 45