Commits

Shu Zong Chen  committed 6f0e5f1

Forms now allows custom attrs to be passed to field widgets

  • Participants
  • Parent commits c79a3e4

Comments (0)

Files changed (1)

File contactforms/forms.py

 		fieldsets = []
 		for i, v in enumerate(data['fieldsets']):
 			fieldsets.append((v.get('legend', str(i)).lower(), v))
-		base_form_fields['Meta'] = type('Meta', (), {'fieldsets': fieldsets})
+		meta = {
+			'fieldset': fieldsets,
+		}
+		base_form_fields['Meta'] = type('Meta', (), meta)
 		
 		form = type(
 			'contact_form_'+name,
 
 def yaml_to_field(data):
 	_type = data['type']
-	kwargs = dict((k,v) for k,v in data.items() if k not in ('id', 'type', 'autofocus'))
+	kwargs = dict((k,v) for k,v in data.items() if k not in ('id', 'type', 'autofocus', 'attrs'))
 	if 'required' not in kwargs:
 		kwargs['required'] = False
 	ret = FieldRegistry.get(_type, **kwargs)
 	if data.get('autofocus') is True:
 		ret.widget.attrs.update({'autofocus': 'autofocus'})
+	for k,v in data.get('attrs', {}).iteritems():
+		ret.widget.attrs.update({k: v})
 	return ret