简体   繁体   English

所需的单选字段,没有羊驼毛形式的默认选择

[英]required radio field without default selection in alpaca form

I would like to create a required alpaca radio field where initially no option is selected (I feel that having a default option would influence users).我想创建一个必需的alpaca 无线电字段,最初没有选择任何选项(我觉得拥有默认选项会影响用户)。 I don't want to have a "None" option selected and than validated.我不想选择“无”选项并进行验证。

I couldn't figure out how to do this looking at the documentation: http://www.alpacajs.org/docs/fields/radio.html我无法弄清楚如何查看文档: http : //www.alpacajs.org/docs/fields/radio.html

To make your radio field required you should use the option "required" on your form schema configuration.要使您的无线电字段成为必需,您应该在表单schema配置中使用"required"选项。

"schema": {
  "required": true,
  "enum": ["Vanilla", "Chocolate", "Coffee"]
}

This will tell alpaca not to add a none option to the list and forces you to select an item from the list.这将告诉 alpaca 不要在列表中添加 none 选项并强制您从列表中选择一个项目。 If you don't select any option the submit button will always be disabled because alpaca knows that the form is invalid ( the default behavior of alpaca form validation )如果您不选择任何选项,则提交按钮将始终处于禁用状态,因为 alpaca 知道表单无效( alpaca 表单验证的默认行为

If you want to simuate the validation when you didn't select any option try to change the submit button name from submit to add for exemple.如果您想在未选择任何选项时模拟验证,请尝试将提交按钮名称从submit更改为add ,例如。

"buttons": {
   "add": {

Here's a working fiddle for that.这是一个工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM