Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable client-side form field validation in Django admin

How do you disable client-side JS form field validation in Django's admin, specifically for URLFields?

I have a client that doesn't want to enter "http://" for all URL fields, which seems reasonable. This is easy to do with the server-side form validation, but the client-side still prevents the form from being submitted unless the user enters "http://". How do I turn that off, just for that field? I'm looking through the code for models.URLField/forms.URLField/URLValidator, but I don't see an easy way to turn it off without reimplementing the widget.

Edit: Example of the JS validation I want to disable. enter image description here

like image 369
Cerin Avatar asked Nov 10 '14 18:11

Cerin


People also ask

How do you make a field not editable in Django?

disabled. The disabled boolean argument, when set to True , disables a form field using the disabled HTML attribute so that it won't be editable by users. Even if a user tampers with the field's value submitted to the server, it will be ignored in favor of the value from the form's initial data.

How do you make a field not required in Django?

Just add blank=True in your model field and it won't be required when you're using modelforms . "If the model field has blank=True , then required is set to False on the form field. Otherwise, required=True ."

How does Django validate form data?

You can use is_valid() when required to validate complete form-data. This validation will check for Python-datatypes. This function will return True or False (Python Data Types) in return.

What is cleaned_data Django?

cleaned_data returns a dictionary of validated form input fields and their values, where string primary keys are returned as objects. form. data returns a dictionary of un-validated form input fields and their values in string format (i.e. not objects).


1 Answers

As I said in the comment, Django doesn't do any client-side validation. The error you're seeing is coming from the browser's own HTML5 validation: see this website for an example and explanation.

You can disable HTML5 validation by adding novalidate to the surrounding form element.

like image 63
Daniel Roseman Avatar answered Oct 20 '22 04:10

Daniel Roseman