Преглед на файлове

Improve field validation to better handle new types

Angus McLeod преди 7 години
родител
ревизия
080bb7e49c
променени са 1 файла, в които са добавени 20 реда и са изтрити 4 реда
  1. 20 4
      assets/javascripts/wizard/initializers/custom.js.es6

+ 20 - 4
assets/javascripts/wizard/initializers/custom.js.es6

@@ -153,7 +153,15 @@ export default {
       }.property('field.type', 'field.id')
     });
 
+    const StandardFields = ['text', 'textarea', 'dropdown', 'image', 'checkbox', 'user-selector', 'text-only'];
+
     FieldModel.reopen({
+      hasCustomCheck: false,
+
+      customCheck() {
+        return true;
+      },
+
       check() {
         let valid = this.get('valid');
 
@@ -162,13 +170,21 @@ export default {
           return true;
         }
 
-        if (!this.get('customValidation')) {
+        const hasCustomCheck = this.get('hasCustomCheck');
+        if (hasCustomCheck) {
+          valid = this.customCheck();
+        } else {
           const val = this.get('value');
-          valid = val && val.length > 0;
-
-          this.setValid(valid);
+          const type = this.get('type');
+          if (type === 'checkbox') {
+            valid = val;
+          } else if (StandardFields.indexOf(type) > -1) {
+            valid = val && val.length > 0;
+          }
         }
 
+        this.setValid(valid);
+
         return valid;
       }
     });