在task.json "Required" 中可以有表达式吗?
In task.json "Required" can have a expression or not?
在Task.json
中,可以为每个输入字段保留必填字段。这将验证该字段是否为必填字段。
如果上述字段的值是“ABCD”,我想创建一个字段 required = true
;如果上述字段的值是其他值,我想创建一个字段 required = false
。我怎样才能做到这一点?在这两种情况下,我都必须显示该字段。
我可以添加表达式来评估
{
"name": "path",
"type": "string",
"label": "Path",
"required": "false",
"validation": {
"expression":"isMatch(value,'^$|\.(?i:)(?:png|jpeg)$','IgnoreCase')",
"message": "Choose a valid file."
},
"helpMarkDown": "Provide a path"
},
我们需要在task.json文件中定义字段1的值,然后select字段1的值来配置字段值,可以参考power shell task来实现.
Task.json 样本:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"required": false,
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
},
{
"name": "path",
"type": "filePath",
"label": "Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
}
{
"name": "path1",
"type": "filePath",
"label": "Path1",
"visibleRule": "targetType = filePath",
"required": false,
"defaultValue": "",
"helpMarkDown": ""
}
]
然后我们就可以在task.ts文件中使用,设置表达式。
另外,如果不想更改字段2名称,我们可以在不同的json文件中定义相同的字段2,在task.ts字段中使用
尚未实现向必填字段添加表达式。这是允许的吗?怎么可能。
我的替代解决方案是让两个不同的输入条目具有相同的标签和相反的 visibleRule。所以在代码中,我应该在访问用户输入之前检查相同的 visibleRule 条件。
示例:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath1",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a mandatory field"
},
{
"name": "filePath2",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = path",
"required": false,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a optional field"
}
]
在代码中访问这些字段时。
var path;
var targetPath = tl.getInput("targetPath1");
If(targetPath == "filePath")
path = tl.getInput("filePath1");
If(targetPath == "path")
path = tl.getInput("filePath2");
在Task.json
中,可以为每个输入字段保留必填字段。这将验证该字段是否为必填字段。
如果上述字段的值是“ABCD”,我想创建一个字段 required = true
;如果上述字段的值是其他值,我想创建一个字段 required = false
。我怎样才能做到这一点?在这两种情况下,我都必须显示该字段。
我可以添加表达式来评估
{
"name": "path",
"type": "string",
"label": "Path",
"required": "false",
"validation": {
"expression":"isMatch(value,'^$|\.(?i:)(?:png|jpeg)$','IgnoreCase')",
"message": "Choose a valid file."
},
"helpMarkDown": "Provide a path"
},
我们需要在task.json文件中定义字段1的值,然后select字段1的值来配置字段值,可以参考power shell task来实现.
Task.json 样本:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"required": false,
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
},
{
"name": "path",
"type": "filePath",
"label": "Path",
"visibleRule": "targetType = filePath",
"required": true,
"defaultValue": "",
"helpMarkDown": ""
}
{
"name": "path1",
"type": "filePath",
"label": "Path1",
"visibleRule": "targetType = filePath",
"required": false,
"defaultValue": "",
"helpMarkDown": ""
}
]
然后我们就可以在task.ts文件中使用,设置表达式。
另外,如果不想更改字段2名称,我们可以在不同的json文件中定义相同的字段2,在task.ts字段中使用
尚未实现向必填字段添加表达式。这是允许的吗?怎么可能。
我的替代解决方案是让两个不同的输入条目具有相同的标签和相反的 visibleRule。所以在代码中,我应该在访问用户输入之前检查相同的 visibleRule 条件。 示例:
"inputs": [
{
"name": "targetPath1",
"type": "radio",
"label": "targetPath",
"defaultValue": "filePath",
"helpMarkDown": "Target script type: File Path or path",
"options": {
"filePath": "File Path",
"path": "Path"
}
},
{
"name": "filePath1",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = filePath",
"required": true,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a mandatory field"
},
{
"name": "filePath2",
"type": "filePath",
"label": "Script Path",
"visibleRule": "targetType = path",
"required": false,
"helpMarkDown": "If the user selects the "File Path" above then Script Path will be a optional field"
}
]
在代码中访问这些字段时。
var path;
var targetPath = tl.getInput("targetPath1");
If(targetPath == "filePath")
path = tl.getInput("filePath1");
If(targetPath == "path")
path = tl.getInput("filePath2");