I'm setting up dynamic form fields that admins can add questions to the form themselves and have us not worry about adding anything.
These are fairly simple questions and are going to be validated just in the ajax validation script and amended to the current error message. (no real need for php validation, I'd love to add this but I just can't get the cvalidation working for fields that are added dynamically)
The issue I'm having is aiming at the custom class I've put in the label for every field that has the required class applied to it. In this case it's "required label".
My guess to just have a blanket look at the label is..
'afterValidate'=>"js:function(form, data, hasError) {
if(document.forms['user-form'].required-label.value == '') {
$('<li>Field cannot be blank</li>').appendTo('#user-form_es_');
$('.required-label').css( 'border-color', '#a94442 ' );
$('label[for=requiredField]').css('color','#a94442 ');
}
else {
$('.required-label').css( 'border-color', '#3c763d ' ) ;
$('label[for=.required-label]').css('color','#3c763d ');
return true;
}
}
But the issue is that the value sits alongside the label, not under it. They are all nested in a form-group class.
Any ideas how to target this label class or is there a better way to go about this?
Edit. Should have noted, the obvious thing is to add required to the input element. The issue is that there is radio buttons and dropdowns that can be marked as required too.