开发者

jquery radio button group problem

开发者_如何学编程

I have a radio group which is validated for required. It works fine except when in certain cases I need to disabled first radio button leaving user to select one from remaining. Even in this case radios are validated but error message is not displayed. I believe its due to error message's association with first radio. Disabling other radio except first works fine too. Is there way around?


You might look at some of the conditional validation questions

  • Link 1
  • Link 2


I'm using the jQuery Validate 1.6 plugin, and after checking the 1.7 changelogs, it doesn't look like it's been fixed.

The reason why this is happening is because there's a bug in the validate plugin where if the first radio button is disabled, the rest of the radio buttons in that group are not considered invalid.

If you step through the plugin code, you'll see in the defaultShowErrors function, it will first highlight your radio group, then unhighlight it.

You can fix this in your own unhighlight method by adding this before you do any unhighlighting.

Note: This is a bandaid solution.

if (this.invalid[$e.attr('name')] !== undefined) { return; }

This checks if the radio group name is listed in the invalid list. If it is, it will stop unhighlighting.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜