The "options" field is not being validated because the "optionsValidate" function is not being called correctly. Instead of looping through the "value" array and calling the "contentValidate" function for each element, it is currently only called once with the entire "value" array.

To fix this, you can modify the "optionsValidate" function to loop through each element of the "value" array and call the "contentValidate" function for each element individually. Here's an updated version of the code:

let optionsValidate = (rule, value, callback) => {
  if (this.questionDialog.question.type <= 1) { //判断是否是选择题
    if (value.length === 0) {
      callback(new Error("选择题必须输入选项"))
    } else {
      let error = false;
      value.forEach(v => {
        contentValidate(rule, v, (err) => {
          if (err) {
            error = true;
            callback(err);
          }
        });
      });
      if (!error) {
        callback();
      }
    }
  } else {
    callback();
  }
}

In this updated version, a variable "error" is introduced to keep track of whether any validation errors occur. Inside the forEach loop, if an error is encountered, the "error" variable is set to true and the callback is called with the error. After the loop, if no errors were encountered, the callback is called without any arguments to indicate successful validation.

data let contentValidate = rule value callback = if typeof value === object if valuelength === 0 callbacknew Error; else callback; else i

原文地址: https://www.cveoy.top/t/topic/i4UZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录