[英]FormIO - Dynamic labels for Text Field based on the input data of another text field
In my form, I have 2 text fields, Based on the user input from the input field 1, the label of the 2nd field should change.在我的表单中,我有 2 个文本字段,根据输入字段 1 的用户输入,第二个字段的 label 应该更改。 Input 1 label: Name Input 2 label: User, Please enter your age
Input 1 label: Name Input 2 label: User, Please enter your age
Now when the user enters the name as John, Label 2 should be changed from 'User, Please enter your age' to 'John, Please enter your age'.现在,当用户输入姓名 John 时,Label 2 应从“用户,请输入您的年龄”更改为“John,请输入您的年龄”。
` `
{
"title": "Page 1",
"label": "Page 1",
"type": "panel",
"key": "page1",
"components": [
{
"label": "Name",
"key": "name",
"type": "textfield",
"input": true,
"tableView": true
},
{
"label": "{{ row.name}}, Please enter your age",
"redrawOn": "name",
"key": "age",
"type": "textfield",
"input": true,
"tableView": true
}
],
"input": false,
"tableView": false
}
If I set label to " {{row.name}}, Please enter your age", Initially when the form load there will not be any data in the name field, so the 2nd label is ", Please enter your age".如果我将 label 设置为“{{row.name}},请输入您的年龄”,最初加载表单时名称字段中不会有任何数据,因此第二个 label 为“,请输入您的年龄”。
Is it possible to have "user", ie "User, Please enter your age" until the name value is entered?在输入名称值之前是否可以有“用户”,即“用户,请输入您的年龄”?
Here is the workaround I followed这是我遵循的解决方法
{{row.name}}
to dummy variable {{data.name1}}
{{row.name}}
更改为虚拟变量{{data.name1}}
if (data.name === "") {
data.name1="User";
}else{
data.name1=data.name;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.