jQuery 验证 - 需要回答所有问题或选择退出调查
我们有一份注册表,要求提供人口统计信息,还可以选择不提供任何信息。 但是,为了保持我们的数字正确相加,如果您选择任何人口统计数据,我们希望要求您输入所有信息。 表格渲染:
- 性别
- ( ) 男
- ( ) 女
- 残疾?
- ( ) 是
- ( ) 否
- 种族
- ( ) A
- ( ) B
- ( ) C
- ( ) 我不想提供人口统计信息
我们希望允许选择“我不希望...”和所有选项,例如“男性/是/A” ,但不是部分答案,例如“女性/C”。
我们如何构建 .validate() 规则和选项来实现这一目标? 理想情况下,如果您的回复不充分,我们将显示/隐藏单个标签。
其他信息:
- 使用 jQuery 验证插件
- 人口统计类型是从数据库列表动态创建的
We have a registration form that asks for demographic information with the additional option to not provide any information. However, to keep our numbers adding up properly, we want to require you to enter all information if you select any demographics. A rendering of the form:
- Gender
- ( ) Male
- ( ) Female
- Disabilities?
- ( ) Yes
- ( ) No
- Race
- ( ) A
- ( ) B
- ( ) C
- ( ) I do not wish to provide demographic information
We want to allow selection of "I do not wish..." and all options, e.g. "Male/Yes/A", but not partial answers, e.g. "Female/C".
How can we structure the .validate() rules and options to achieve this goal? Ideally, we would have a single label show/hide if your response is not sufficient.
Additional information:
- Using the jQuery Validation Plugin
- Demographics types are dynamically created from a database list
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用 jQuery 验证 插件。 如果是这样,您需要的是自定义 需要进行依赖项检查的规则< /a> 允许您在用户未选择退出的情况下进行所需的输入。 您可能希望在选择退出时有一个单击处理程序来清除其他字段,这样当用户选择退出时您就不必检查部分条目。
I'm assuming that you are using the jQuery validation plugin. If so, what you want is a custom require rule with a dependency check that allows you to make the inputs required iff the user does not choose to opt out. You might want to have a click handler on the opt-out that clears the other fields so that you don't have to check for partial entries when the user does choose to opt out.