views:

15

answers:

1

I'm using monorail and jQuery validation. The issue is that when you use the FormHelpers, such as:

$FormHelper.TextField("user.username")

It generates the following html:

<input type="text" value="" name="user.username" id="user_username">

It also generates the following jQuery validate rule (via activerecord's ValidateRegExp attribute):

"user.username":{  required: "This is a required field" , regExp: "Invalid" }

The issue is that the auto-generated id has an underscore instead of a period so jQuery can't find it when setting focus on an invalid field.

This seems like an inherent issue in monorail, activerecord, and jQuery integration. How do people get around this issue? In some cases you can just create the html manually and ensure the id and form attributes are the same, but in many cases you need to use the FormHelpers, as when editing forms the values are not populated unless you use these helpers I've found.

A: 

The helpers are just a wrapper around string concatenation. for e.g., for you value to be populated you can <input type="text" .... value="<%=user.username%>" />

As for jQuery validation rules, AFAIK it does need to specify form fields by their name attribute and not by the id attribute

Ken Egozi