0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2025-02-09 22:47:02 +01:00
discourse-custom-wizard/assets/javascripts/wizard/components/validator.js.es6

43 Zeilen
1,2 KiB
Text

2021-01-26 13:35:10 +05:30
import Component from "@ember/component";
import { not } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
import { getToken } from "wizard/lib/ajax";
2021-01-26 13:35:10 +05:30
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
init() {
this._super(...arguments);
if (this.get('validation.backend')) {
// set a function that can be called as often as it need to
// from the derived component
this.backendValidate = (params) => {
return ajax('/realtime-validations', {
data: {
validation: this.get('name'),
authenticity_token: getToken(),
...params
}
});
}
}
},
2021-01-30 23:16:04 +05:30
didInsertElement() {
this.appEvents.on('custom-wizard:validate', this, this.checkIsValid);
2021-01-26 13:35:10 +05:30
},
2021-01-30 23:16:04 +05:30
willDestroyElement() {
this.appEvents.off('custom-wizard:validate', this, this.checkIsValid);
},
checkIsValid() {
this.set('isValid', this.validate());
2021-01-30 23:16:04 +05:30
}
2021-01-26 13:35:10 +05:30
});