The required required attributes for form validation in Element UI cannot respond dynamically?

the problem encountered now: in a form, there are An and B select drop-down boxes. When A drop-down box contains a specific value, B drop-down box is required, otherwise it is optional. I tried to write this in rules:

    rules:{    
        overseasStudents:[{ required:!this.overseasStatus,message:"",trigger:"blur" }] 
    }

realize the value of required by manipulating the Boolean value of required , but no, I just want to recognize the initialization value. If the initialization is true, it is required, and later changes will not respond. (the version of ElementUI I use is 1.4)


<el-form-item label="1" prop="govtOrgLevel" :rules="{required:newBasicForm.isGovtWork == '1'? true:false,message:''}">
     <el-select v-model="newBasicForm.govtOrgLevel" placeholder="" :disabled="newBasicForm.isGovtWork == '1'? false:true">
        <el-option
          v-for="item in orgLevelOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
</el-form-item>

has been resolved. (code directly)

                     <el-form-item label="1" prop="govtOrgLevel" :required="newBasicForm.isGovtWork == '1'? true:false">
                         <el-select v-model="newBasicForm.govtOrgLevel" placeholder="" :disabled="newBasicForm.isGovtWork == '1'? false:true">
                            <el-option
                              v-for="item in orgLevelOptions"
                              :key="item.value"
                              :label="item.label"
                              :value="item.value">
                            </el-option>
                          </el-select>
                      </el-form-item>

you need to listen to this property and be sure to add $nextTick (). If you do not add a required attribute, it will trigger the validation that comes with the framework and XX is required will appear.

  'newBasicForm.isGovtWork'(val){
    this.$nextTick(()=>{
    if(val !== '1'){
        this.$refs.newBasicForm.validateField('govtOrgLevel');
        this.newBasicForm.govtOrgLevel='';// ,

    }
    })
  },

you don't need to add requied in rules


    trigger: ["blur", "change"]


change time:

  

Brother, why don't you just write the rules inside, even if it's so troublesome to monitor!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be0bcb-31524.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be0bcb-31524.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?