[Answered ]-Removing initial value from form

2👍

You can play with the submitted values by overriding clean_foo() method for field.

class StoreForm(forms.Form):
    title = forms.CharField()
    link = forms.URLField(verify_exists=True, required=False, initial='http://')

    def clean_link(self):
        data = self.cleaned_data['link']
        if data == 'http://':
            return ''
        else:
            return data
👤aabele

0👍

Proper way of doing this I think would be extend the default widget and override value_from_datadict method as can be seen here:

You could also override clean() method on Field (extend URLField).

Idea would be to check if value == initial and return None in that case.

Also keep in mind that verify_exists has some security issues as can be seen here:
https://www.djangoproject.com/weblog/2011/sep/09/security-releases-issued/ (Denial of service attack via URLField)

Leave a comment