form icon indicating copy to clipboard operation
form copied to clipboard

form 如何获取字段的 rules 等信息

Open tolerance-go opened this issue 5 years ago • 0 comments

准备实现一个 validate 静默版本

   const fieldsProps = columns
          .map(item => {
            return item.dataIndex;
          })
          .reduce((obj, dataIndex) => {
            obj[dataIndex] = this.props.form.getFieldProps(dataIndex); // 这里 getFieldProps 应该使用方法是不对的,就是想获取 rules 等信息
            return obj;
          }, {});

        const schemaConfig = _.mapValues(fieldsProps, (meta, dataIndex) => {
          return meta['data-__meta'].rules || [];
        });

        const validator = new schema(schemaConfig);

    const values = this.props.form.getFieldsValue();
        validator.validate(values, errors => {
          resolve({ errors, values });
        });

但是页面上会出现 validating 状态 可不可以暴露一个方法用来获取字段信息

tolerance-go avatar Apr 22 '19 05:04 tolerance-go