diff --git a/assets/javascripts/wizard/components/field-validators.js.es6 b/assets/javascripts/wizard/components/field-validators.js.es6 new file mode 100644 index 00000000..8607379c --- /dev/null +++ b/assets/javascripts/wizard/components/field-validators.js.es6 @@ -0,0 +1,9 @@ +import Component from "@ember/component"; +import { observes } from "discourse-common/utils/decorators"; +export default Component.extend({ + actions:{ + perform() { + this.toggleProperty('performValidation'); + } + } +}); \ No newline at end of file diff --git a/assets/javascripts/wizard/components/validator.js.es6 b/assets/javascripts/wizard/components/validator.js.es6 new file mode 100644 index 00000000..9eb3ad6c --- /dev/null +++ b/assets/javascripts/wizard/components/validator.js.es6 @@ -0,0 +1,16 @@ +import Component from "@ember/component"; +import { not } from "@ember/object/computed"; +import { observes } from "discourse-common/utils/decorators"; + +export default Component.extend({ + classNameBindings: ['isValid', 'isInvalid'], + validMessageKey: null, + invalidMessageKey: null, + isValid: null, + isInvalid: not('isValid'), + layoutName: 'components/validator', // useful for sharing the template with extending components + @observes('perform') + performValidation() { + this.validate(); + }, +}); \ No newline at end of file diff --git a/assets/javascripts/wizard/templates/components/field-validators.hbs b/assets/javascripts/wizard/templates/components/field-validators.hbs new file mode 100644 index 00000000..197fd112 --- /dev/null +++ b/assets/javascripts/wizard/templates/components/field-validators.hbs @@ -0,0 +1,13 @@ +{{#if field.validations}} + {{#each field.validations.top as |validation|}} + {{validation.component field=field perform=perform}} + {{/each}} + + {{yield (hash perform=(action 'perform')) }} + + {{#each field.validations.bottom as |validation|}} + {{validation.component field=field perform=perform}} + {{/each}} +{{else}} + {{yield}} +{{/if}} diff --git a/assets/javascripts/wizard/templates/components/validator.hbs b/assets/javascripts/wizard/templates/components/validator.hbs new file mode 100644 index 00000000..09a4c262 --- /dev/null +++ b/assets/javascripts/wizard/templates/components/validator.hbs @@ -0,0 +1,5 @@ +{{#if isValid}} + {{i18n validMessageKey}} +{{else}} + {{i18n invalidMessageKey}} +{{/if}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field.hbs b/assets/javascripts/wizard/templates/components/wizard-field.hbs index 5f524e92..8f342e54 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field.hbs @@ -10,11 +10,13 @@