FormBuilder: Add class to field instead of containing DIV

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
admsh
Forum Members
Forum Members
Posts: 93
Joined: Tue Aug 19, 2008 6:30 pm
Location: NY

FormBuilder: Add class to field instead of containing DIV

Post by admsh »

I'm trying to add jquery validation to a form instead of using formbuilder's built in validation. Problem is the validation plugin identifies required fields by their class (.required), and FormBuilder adds a class to the DIV containing the form elements...

Tried looking in the form template but can't find the solution there...

Any help would be hugely appreciated...
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: FormBuilder: Add class to field instead of containing DI

Post by Foaly* »

this isn't possible without either hacking the core or using a dirty reeplace modifier solution. are you sure there is no option to change jquery's selector from .required to .required input?
admsh
Forum Members
Forum Members
Posts: 93
Joined: Tue Aug 19, 2008 6:30 pm
Location: NY

Re: FormBuilder: Add class to field instead of containing DI

Post by admsh »

yes, i'm sure. one can specify the fields to validate using their name attribute, but then making a field required in formbuilder's back-end makes no difference on the validation...

if the fields themselves got the "required" class attached to them, no other code would be needed...
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: FormBuilder: Add class to field instead of containing DI

Post by Foaly* »

I'd not suggest to use one of the above-mentioned solutions. What validation plugin are you using?
admsh
Forum Members
Forum Members
Posts: 93
Joined: Tue Aug 19, 2008 6:30 pm
Location: NY

Re: FormBuilder: Add class to field instead of containing DI

Post by admsh »

this one:
http://docs.jquery.com/Plugins/validation

if the required class could be added to the form element, it would look like this:

Code: Select all

 <__script__>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
 </__script>
as it is now it would have too look like this:

Code: Select all

<__script__>
  $(document).ready(function(){
    $("#commentForm").validate({
        $.validator.classRuleSettings = {
	mandatory: {required:true}, //originally required
	email: { email: true },
	url: { url: true },
	date: { date: true },
	dateISO: { dateISO: true },
	dateDE: { dateDE: true },
	number: { number: true },
	numberDE: { numberDE: true },
	digits: { digits: true },
	creditcard: { creditcard: true }
        };
    });
  });
 </__script>
Foaly*
Translator
Translator
Posts: 150
Joined: Sun Mar 29, 2009 3:32 pm
Location: London

Re: FormBuilder: Add class to field instead of containing DI

Post by Foaly* »

it seems to me that you are right.. that's strange that there's no option that defines the required class name.
optart
Forum Members
Forum Members
Posts: 85
Joined: Thu Mar 11, 2010 9:01 am

Re: FormBuilder: Add class to field instead of containing DI

Post by optart »

you can do it also via script:

jQuery("#formID").addClass(function() {
return $(this).parent('div').attr('class')});
dmgd
Forum Members
Forum Members
Posts: 115
Joined: Tue Jun 06, 2006 1:10 pm
Location: TX

Re: FormBuilder: Add class to field instead of containing DI

Post by dmgd »

This works for the default formbuilder style.

Code: Select all

 <__script__ type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></__script>
<__script__>
{literal}
  $(document).ready(function(){
           $("input").each(function() {
                  if( $(this).parent().hasClass("required") ) {
                       $(this).addClass("required");
                   }
            });
 });
{/literal}
</__script>
Post Reply

Return to “Modules/Add-Ons”