0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00

Improve field validation to better handle new types

Dieser Commit ist enthalten in:
Angus McLeod 2018-02-04 14:34:32 +08:00
Ursprung b66999f845
Commit 080bb7e49c

Datei anzeigen

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