0

使用 KnockoutJS + JQuery Validation,所有控件验证工作正常。虽然 Radio btn 验证不起作用。

问题 1: * 显示在收音机 btn 附近

男 女

输出:*男性预期输出:男性*输出:*女性预期输出:女性*

问题 2:在应用 Class=Required 时,两个单选按钮都是必需的,我们将如何解决该问题

问题 3:动态单选按钮也发生了同样的事情。所有这些都可以在同一页面中找到。

引导我......

4

2 回答 2

1

尝试淘汰赛验证,它与淘汰赛一起工作得更好

https://github.com/ericmbarnard/Knockout-Validation

于 2012-08-14T07:38:56.280 回答
0
  1. Make sure your radio buttons have the same "name" attribute (this is the case with jquery validation regardless of using knockout)

  2. You only need to add required class to one of them if you do my first point above

  3. Dynamic radio buttons need to have specific names (and names need to be same for all buttons you want to validate in a group)

For instance, I have this foreach loop that validates the radiobuttons correctly because they have unique names

<input type="radio" data-bind="attr: { name: 'options-' + $index() }" class="required" value="Yes" checked />
<input type="radio" data-bind="attr: { name: 'options-' + $index() }" value="No" checked />
于 2013-02-19T20:16:23.800 回答