表单使用验证
实现场景:
表单中我想要选项选择A的时候,标签只能选择2,选项选择B的时候,标签只能选择1和3,求解,怎么联动!!
{
"type":"page",
"title":"Hello world",
"body":[
{
"type":"form",
"title":"表单",
"controls":[
{
"type":"select",
"label":"选项",
"name":"select",
"options":[
{
"label":"A",
"value":"A"
},
{
"label":"B",
"value":"B"
}
]
},
{
"type":"tag",
"label":"标签",
"name":"tag",
"options":[
"1",
"2",
"3"
],
"optionsTip":"最近您使用的标签"
}
]
}
]
}
这个文档里面描述的是必填项,但是不能指定只能选择那一项呀
option上配置disabledOn
{
type: 'tag',
label: '标签',
name: 'tag',
options: [
{
label: '1',
value: '1',
disabledOn: 'data.select === "A"'
},
{
label: '2',
value: '2'
},
{
label: '3',
value: '3'
}
],
optionsTip: '最近您使用的标签'
}
感谢!
这样配置表单联动不可以吗?值变动监听的时候难道multiple这个值不会变化吗,获取变化了也不起作用了?
{
"type": "page",
"title": "Hello world",
"body": [
{
"type": "form",
"title": "表单",
"controls": [
{
"type": "select",
"label": "选项",
"name": "select",
"multiple": true,
"options": [
{
"label": "A",
"value": "A"
},
{
"label": "B",
"value": "B"
}
]
},
{
"type": "select",
"label": "标签",
"name": "tag",
"multiple": "data.select.split(',').length === 1",
"options": [
{
"label": "1",
"value": "1"
},
{
"label": "2",
"value": "2"
},
{
"label": "3",
"value": "3"
}
],
"optionsTip": "最近您使用的标签"
}
]
}
]
}
大佬求解!
multipe 不支持表达式,可以来两个表单项,然后 visibleOn 来切换
好的,感谢回复!
请问想达到修改一个表单项的值的时候,联动设置另一个表单项的值,请问怎么设置?貌似value也不支持表达式,查看文档表单联动的只看到显示隐藏禁用等功能,没有看到设置值的功能
{
"type": "page",
"body": {
"type": "form",
"controls": [
{
"label": "选项",
"type": "select",
"name": "select",
"multiple": true,
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
},
{
"label": "C",
"value": "c"
}
]
},
{
"type": "text",
"name": "name",
"label": "姓名:",
"value":"data.select==='a' ? '1' : '2'"
}
]
}
}
搜formula
好的,感谢