Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当字段格式是object时,怎么验证必填呢 #19

Closed
cky917 opened this issue Sep 12, 2018 · 1 comment · Fixed by #20
Closed

当字段格式是object时,怎么验证必填呢 #19

cky917 opened this issue Sep 12, 2018 · 1 comment · Fixed by #20
Assignees

Comments

@cky917
Copy link

cky917 commented Sep 12, 2018

https://vipshop.github.io/ncform/ncform-theme-elementui/index.html 类似例子中的[compound.prependSelect: 前置下拉框 / 本地数据源] 情况。 想验证user.name必填
require校验总是通过的

@daniel-dx
Copy link
Collaborator

daniel-dx commented Sep 12, 2018

当为对象时,如果对象是个空对象,会正确触发必填校验
这里比较特殊是,如果下拉框选择了值,那对象其实是有值的,而你的场景是想填了文本框才算校验通过,所以可以结合customRule来实现

注意: @ncform/ncform-theme-elementui 需要升级到0.1.14版本

示例代码如下:
打开playground
复制以下配置查看效果

{
  "type": "object",
  "properties": {
    "user": {
      "type": "object",
      "ui": {
        "widget": "input",
        "widgetConfig": {
          "modelField": "name",
          "compound": {
            "prependSelect": {
              "itemLabelField": "label",
              "itemValueField": "value",
              "enumSource": [
                {
                  "value": 1,
                  "label": "男"
                },
                {
                  "value": 2,
                  "label": "女"
                }
              ],
              "modelField": "gender"
            }
          }
        }
      },
      "rules": {
        "required": true,
        "customRule": [
          {
            "script": "dx: {{$root.user}}.name",
            "errMsg": "名字必填"
          }
        ]
      }
    }
  }
}

@daniel-dx daniel-dx reopened this Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants