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.
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.
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 ."
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.
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).
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.
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