antd form.getFieldsValue(true) usage

Manually push a custom attribute in the component, which is not managed uniformly by the form instance.

form.setFieldsValue({ isWarn: true })

Component area B of the form form

 const {
    
     a, b } = res || {
    
    }
 if (a && b) {
    
    
   form.setFieldsValue({
    
     isWarn: true })
 } else {
    
    
   form.setFieldsValue({
    
     isWarn: false })
 }

Because it is not under the unified management of the form, form.getFieldsValue()when using the get attribute, you need to pass in a true value to display the custom attribute

Component area A of the form form

<Form.Item
	name={
    
    ['sinkTable', 'allInfo']}
	label="表名"
	rules={
    
    
	  [
		() => ({
    
    
		  validator() {
    
    
		    const {
    
     isWarn } = form.getFieldsValue(true)
		    if (isWarn) {
    
    
		      return Promise.reject(new Error('警告提示'))
		    }
		    return Promise.resolve()
		  },
		}),
	  ]
	}
>
/*忽略内容*/

Guess you like

Origin blog.csdn.net/qq_29493173/article/details/126783148