﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5329	URLField initial value, fails on validation	danielrubio	Adrian Holovaty	"Caught one more bug on new forms, this one is related to URLField. 

If your form has the following declaration: 
site = forms.URLField(required=False,initial='http://')

'http://' is placed by default on the form, however, validation fails even though 'required=False' is also used. So the user is forced to either introduce a valid URL or delete the 'http://' snippet from the box. 

The reason behind the bug is that the 'initial' parameter is never taken into account in field.py, under django/newforms 
To fix, its necessary to modify the clean method on the RegEx field class (Line: 316), to read like follows: 

  def clean(self, value):
        """"""
        Validates that the input matches the regular expression. Returns a
        Unicode object.
        """"""
        value = super(RegexField, self).clean(value)
        if value == u'':
            return value
       ''' if value == self.initial:
            return None'''
        if not self.regex.search(value):
            raise ValidationError(self.error_message)
        return value

The if value == self.initial return None, will fix the validation error. NOTE: The fix is in the RegEx field, on account the URLField delegates validation up to this class. 


  


"		closed	Forms	dev		wontfix			Unreviewed	0	0	0	0	0	0
