1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1026 Views |
-
using jquery for form validation, how do i change the class attr of an input?

1 October 2010 at 6:47pm Last edited: 1 October 2010 6:48pm
Hey guys,
So prototype was being an exceptional PITA wtih all my other jquery ajax and UI stuff so in order to simplify my site i've got rid of all the prototype validation. The problem is that now the easiest way to use jQuery's validation plugin is just to simply add, to the class attribute of each input, "required". I've seen the ssbits tutorial, but it's pretty hacky when one can do it this way. Is there any way to simply add an extra class definition to my form code, without creating a whole separate template for it, and end all the time i'm wasting trying to get this working, or do I have to keep dealing with writing a whole new bunch of JS rules per form?
-
Re: using jquery for form validation, how do i change the class attr of an input?

1 October 2010 at 9:35pm Last edited: 1 October 2010 9:40pm
I solved it this way:
//add fields
$details = new CompositeField(
$Name = new TextField("Name", _t("Member.NAME","Naam")),
$Email = new TextField("Email", _t("Member.EMAIL","Email")),
$Tel = new TextField("Tel", _t("Member.PHONE","Telefoon") )
);//required array
$defaultRequired = array('Name', 'Email', 'Tel');// add required class to the required fields
foreach($defaultRequired as $req){
${$req}->addExtraClass('required');
}// add them to required fields for serverside validation
$v = new RequiredFields($defaultRequired);Edit:
Here is a slightly different way, which uses the fieldByName on a FieldSet.
http://silverstripe.org/form-questions/show/251573?start=8#post293059
-
Re: using jquery for form validation, how do i change the class attr of an input?

3 October 2010 at 1:58pm
perfect, thanks for that!
| 1026 Views | ||
|
Page:
1
|
Go to Top |


