Skip to content

Commit

Permalink
Issue agiliq#29 - Parsley 1.2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit Chachra committed Nov 22, 2013
1 parent 1438f31 commit dbe1ab8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions parsley/decorators.py
Expand Up @@ -23,18 +23,18 @@
def update_widget_attrs(field):
attrs = field.widget.attrs
if field.required:
attrs["data-required"] = "true"
attrs["required"] = "required"

error_message = field.error_messages.get('required', None)
if error_message:
attrs["data-required-message"] = error_message
attrs["parsley-error-message"] = error_message

if isinstance(field, forms.RegexField):
attrs.update({"data-regexp": field.regex.pattern})
attrs.update({"parsley-regexp": field.regex.pattern})

error_message = field.error_messages.get('invalid', None)
if error_message:
attrs["data-regexp-message"] = error_message
attrs["parsley-error-message"] = error_message

if field.regex.flags & re.IGNORECASE:
attrs.update({"data-regexp-flag": "i"})
Expand All @@ -45,20 +45,20 @@ def update_widget_attrs(field):
# Set data-* attributes for parsley based on Django field attributes
for attr, data_attr, in FIELD_ATTRS:
if getattr(field, attr, None):
attrs["data-{0}".format(data_attr)] = getattr(field, attr)
attrs["parsley-{0}".format(data_attr)] = getattr(field, attr)

error_message = field.error_messages.get(attr, None)
if error_message:
attrs["data-{0}-message".format(data_attr)] = error_message
attrs["parsley-{0}-message".format(data_attr)] = error_message

# Set data-type attribute based on Django field instance type
for klass, field_type in FIELD_TYPES:
if isinstance(field, klass):
attrs["data-type"] = field_type
attrs["parsley-type"] = field_type

error_message = field.error_messages.get('invalid', None)
if error_message:
attrs["data-type-{0}-message".format(field_type)] = error_message
attrs["parsley-type-{0}-message".format(field_type)] = error_message


def parsleyfy(klass):
Expand All @@ -80,7 +80,7 @@ def new_init(self, *args, **kwargs):
value = '#' + self[value].id_for_label
if isinstance(value, bool):
value = "true" if value else "false"
attrs['data-%s' % key] = value
attrs['parsley-%s' % key] = value
klass.__init__ = new_init

try:
Expand Down

0 comments on commit dbe1ab8

Please sign in to comment.