0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 20:41:11 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/validator.js.es6

43 Zeilen
1,1 KiB
Text

2021-01-26 09:05:10 +01:00
import Component from "@ember/component";
import { equal } from "@ember/object/computed";
import { ajax, getToken } from "discourse/lib/ajax";
2021-01-26 09:05:10 +01:00
export default Component.extend({
classNames: ["validator"],
classNameBindings: ["isValid", "isInvalid"],
validMessageKey: null,
invalidMessageKey: null,
isValid: null,
isInvalid: equal("isValid", false),
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: {
type: this.get("type"),
authenticity_token: getToken(),
...params,
},
});
};
}
},
didInsertElement() {
this.appEvents.on("custom-wizard:validate", this, this.checkIsValid);
},
2021-01-30 18:46:04 +01:00
willDestroyElement() {
this.appEvents.off("custom-wizard:validate", this, this.checkIsValid);
},
checkIsValid() {
this.set("isValid", this.validate());
},
});