Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-23 01:40:29 +01:00
frontend validator apis
Dieser Commit ist enthalten in:
Ursprung
505043922e
Commit
3cc45fa714
5 geänderte Dateien mit 50 neuen und 5 gelöschten Zeilen
9
assets/javascripts/wizard/components/field-validators.js.es6
Normale Datei
9
assets/javascripts/wizard/components/field-validators.js.es6
Normale Datei
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
16
assets/javascripts/wizard/components/validator.js.es6
Normale Datei
16
assets/javascripts/wizard/components/validator.js.es6
Normale Datei
|
@ -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();
|
||||||
|
},
|
||||||
|
});
|
13
assets/javascripts/wizard/templates/components/field-validators.hbs
Normale Datei
13
assets/javascripts/wizard/templates/components/field-validators.hbs
Normale Datei
|
@ -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}}
|
5
assets/javascripts/wizard/templates/components/validator.hbs
Normale Datei
5
assets/javascripts/wizard/templates/components/validator.hbs
Normale Datei
|
@ -0,0 +1,5 @@
|
||||||
|
{{#if isValid}}
|
||||||
|
{{i18n validMessageKey}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n invalidMessageKey}}
|
||||||
|
{{/if}}
|
|
@ -10,11 +10,13 @@
|
||||||
<div class='field-description'>{{cookedDescription}}</div>
|
<div class='field-description'>{{cookedDescription}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#field-validators field=field as |validators|}}
|
||||||
{{#if inputComponentName}}
|
{{#if inputComponentName}}
|
||||||
<div class='input-area'>
|
<div class='input-area'>
|
||||||
{{component inputComponentName field=field step=step fieldClass=fieldClass wizard=wizard}}
|
{{component inputComponentName field=field step=step fieldClass=fieldClass wizard=wizard focusOut=validators.perform}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/field-validators}}
|
||||||
|
|
||||||
{{#if field.char_counter}}
|
{{#if field.char_counter}}
|
||||||
{{#if textType}}
|
{{#if textType}}
|
||||||
|
|
Laden …
In neuem Issue referenzieren