Is is possible to give placeholder for a float field in django forms?
I know that We can easily give placeholder for a char field in django like below,
materials_name = forms.CharField(required=False,max_length=200,label= "Material Name", widget=forms.TextInput(attrs={'placeholder': 'Material name'}))
Like this how can i give placeholder for a float field in django forms?
Thanks in advance
To do this in Django currently, you have to do something like: comment = forms. CharField(max_length=200, widget=forms. TextInput({ "placeholder": "Text!"}))
Placeholders are an easy way to define sections in an HTML template that will be filled with content from the database when the page is rendered. This content is edited using django CMS's frontend editing mechanism, using Django template tags. fullwidth.
In order to add a class or id attribute to a form in Django, we have to place a widget=form. TextInput (or widget= form. EmailInput, if email input) within the form field (because it's a text field). Inside of this widget, we then have to put, attrs={'class':'some_class'}.
You can do it in the same way:
materials_float = forms.FloatField(required=False,label= "Material Name", widget=forms.NumberInput(attrs={'placeholder': 'Material float'}))
Or:
materials_decimal = forms.DecimalField(required=False,label= "Material Name", widget=forms.NumberInput(attrs={'placeholder': 'Material decimal'}))
just change Field
UPDATE: As @olofom requested, the widget has been replaced by NumberInput
to render to number
field in HTML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With