From dbe1ab8b6c58168c5ae267241f0c849c9eae631b Mon Sep 17 00:00:00 2001 From: Sumit Chachra Date: Thu, 21 Nov 2013 18:33:18 -0800 Subject: [PATCH] Issue #29 - Parsley 1.2 support. --- parsley/decorators.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/parsley/decorators.py b/parsley/decorators.py index 6bdf646..330d07c 100644 --- a/parsley/decorators.py +++ b/parsley/decorators.py @@ -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"}) @@ -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): @@ -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: