I have a model which contains link = URLField()
. The problem is, I don’t want the client-side to do any kind of validation (i’m doing that in the clean_link
) i.e I want the pattern
in input
to accept anything
I have tried using django-widget-tweaks
such as
mytemplate.html
{% load widget_tweaks %}
<div class="form-group">
{{form.link|attr:"pattern:.*"|as_crispy_field}}
</div>
which has no effect (tested in Firefox). I can include novalidate
in my <form>
but then that’ll remove validations for all my fields, and not only for link
.
Further more I have tried changing it in the form according to the docs
from django import forms
from .models import *
from local.utils.utils import check_link
from django.utils.translation import gettext_lazy as _
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
# change a widget attribute:
self.fields['link'].widget.attrs.update({'pattern': '.*'})
but that does not have any effect at all (the input field is still rendered red, when entering anything apart from the standard validation).
At last I have tried adding
<script>
$(document).ready(function () {
$("#id_link").attr("pattern",".*")
});
</script>
I can see we do indeed change the pattern
but it does not accept everything any way.
How do we properly manage the attributes/properties for <input>
when we are using the Django-form?