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
0
votes
2 answers

Django textarea widget does not have attribute "input_type"

I'm trying to check input type of widget as below: for field in form: if field.field.widget.input_type == 'checkbox': do_smth() else: do_smth_else() but it seems Django Textarea widget does not have attribute "input_type". I…
renkse
  • 502
  • 7
  • 15
0
votes
1 answer

Django-select2 filtering widget data by owner (Related user)

I'm using django-select2 with class based view (create, update, delete view) In CreateView, i'm use form_class in view with my form. In this form i'm use widgets for selecting related objects. And i need filtering these objents by created_user…
0
votes
1 answer

django date picker input in template

I´m trying to use a date picker widget from a model form in the template. I´ve seen several posts but couldn´t get it working correctly. The one I´m trying now is: Answered question Form.py My form code looks like class…
Francisco Ghelfi
  • 872
  • 1
  • 11
  • 34
0
votes
1 answer

Django JSONField not receiving cleaned data

I have a very simple model which contains a JSONField: class Thing(models.Model): title = models.CharField(max_length=1024) text = JSONField(default=dict) I've created a custom widget that allows for the input of key-value pairs: class…
Matthew Trevor
  • 14,354
  • 6
  • 37
  • 50
0
votes
1 answer

Custom Image Widget in with Django

I'm trying to build a custom Image Widget in the following manner: class ImageWidget(forms.widgets.Widget): template_name = 'widgets/picture.html' def get_context(self, name, value, attrs=None): return {'widget': { …
martincho
  • 4,517
  • 7
  • 32
  • 42
0
votes
2 answers

Django widget that depends on model

I am pretty new to django and have a question. I got a ModelForm using Widgets. Since I have a field called discount which I only want to be editable if the displayed model fullfills some requirements, I make it read-only using a widget entry: class…
0
votes
3 answers

Django how to pass choices list to a custom select widget

I need to override select widget. class TooltipSelectWidget(Select) : def __init__(self, *args, **kwargs) : super().__init__(*args, **kwargs) Then I call it in a form. But I do not see in the docs how to pass the choices list to this…
piscvau
  • 21
  • 7
0
votes
3 answers

How to override the default value in dropdown list

In my web application, i have a drop-down list created using ModelForm which is rendering well, however, i can't set default text like "Choose One Option" or "Select One", rather its showing the default "----" which I would love to override I have…
0
votes
1 answer

django: how can I remove the clear and change options from the filefield?

How can I remove the clear and change options from the filefield over here? I think I need to modify class ClearableFileInput(FileInput) but I am not sure how. I have tried below- class MyClearableFileInput(ClearableFileInput): initial_text =…
user2715898
  • 921
  • 3
  • 13
  • 20
0
votes
1 answer

Change model form field to text input widget

I want to change the 'trans_recipient' field widget from being a dropdown, into being a text-input field. In the case of a large I've tried the following : class SafeTransactionForm(forms.ModelForm): ''' SafeTranSactionForm ''' trans_recipient =…
timi95
  • 368
  • 6
  • 23
0
votes
1 answer

How to render default values in django-ajax_select field

I am using ajax_select for my m2m and foreign key fields, its working fine but it is not rendering default value of that field, it is rending empty value ("|"). I am not using ajax_select in my admin panel, so when I open that form in admin panel,…
0
votes
0 answers

Template Widget in Django 2.0 & Crispy form

I would like to change the way a widget is rendered in Django. I've read this guide https://docs.djangoproject.com/en/2.0/ref/forms/renderers/ but still I can't make it working. I've create this widget class…
0
votes
0 answers

Trying to replace default HTML widgets

I'm making a framework to improve the development of an existing system. My main task was to make said system responsive, and we settled in using material design. we're using django version 1.9. We've tried a lot of existing frameworks (django…
0
votes
1 answer

cannot use custom related_widget_wrapper.html

I get TemplateDoesNotExist error if I use custom related_widget_wrapper.html. What I did is, I created a folder called widgets inside templates/dashboard directory and add a related_widget_wrapper.html file. This way I got the mentioned error and…
Serenity
  • 3,884
  • 6
  • 44
  • 87
0
votes
0 answers

Django widget form for get_or_create

I have a Select widget but I need list all of values about a field of Model, and create new values of these field at the same input. With select I can list and choose one value, but can't create news. Whith textinput I can create but not list. What…
Carlosr
  • 28
  • 4