Skip to content

V-form

유효성 검사 직접 구현

  validateForms(): boolean {
    const fields = [
      this.$refs.emailField,
      this.$refs.phone1Field,
      this.$refs.phone2Field,
    ];
    let result = true;
    for (const key in fields) {
      const field = fields[key];
      if (!field) {
        continue;
      }

      const validate = field[V_TEXT_FIELD_VALIDATE];
      if (typeof validate === 'undefined') {
        continue;
      }

      // You need to repeat the validation function for every field.
      if (!validate(true)) {
        result = false;
      }
    }
    return result;
  }

See also