views:

60

answers:

1

I want to add the jquery-form-validator to my customer's old CMS.

This jqery form validator requires to insert a class such as class="validate[required,custom[onlyLetter],length[0,100]]" to input.

<input class="validate[required,custom[onlyLetter],length[0,100]]" name="firstname" type="text" />


Since this is (old from '90) CMS, I need to add class by js like this.

var inputid = $(this).attr("id");

if(inputid=='navn'){
 $(this).removeClass().addClass('validate[required,custom[onlyLetter],length[0,100]] text-input');

}else if(inputid=='e-post'){
 $(this).removeClass().addClass('validate[required,custom[email]] text-input');
}else if (inputid=='telefon'){
 $(this).removeClass().addClass('validate[required,custom[telephone]] text-input');

It add class to input tags as I wanted. However when I add class by js, it does not work. I assume it is because of event delegation.

Can anyone help me how to do in this situation please?

Thanks in advance.

A: 

If addClass isn't working, perhaps it is barfing at the syntax... perhaps:

$(this).attr('class','validate[required,custom[onlyLetter],length[0,100]]');

might work?

(edit)

It also seems likely that the validator is going to read the value once, not continually... perhaps make sure this executes before you initialize the validation library?

Marc Gravell
Thanks Marc. As you pointed out, I just needed to add classes before the validation library.
shin