Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
41 Zeilen
1 KiB
JavaScript
41 Zeilen
1 KiB
JavaScript
import Component from "@ember/component";
|
|
import { equal } from "@ember/object/computed";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
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"),
|
|
...params,
|
|
},
|
|
});
|
|
};
|
|
}
|
|
},
|
|
|
|
didInsertElement() {
|
|
this.appEvents.on("custom-wizard:validate", this, this.checkIsValid);
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this.appEvents.off("custom-wizard:validate", this, this.checkIsValid);
|
|
},
|
|
|
|
checkIsValid() {
|
|
this.set("isValid", this.validate());
|
|
},
|
|
});
|