开发者

jQuery validate set focus on error doesn't work on FormHelper elements

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 o开发者_JAVA技巧n 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜