mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 14:52:46 +08:00
FIX: Debounce group name validation correctly (#13757)
This commit is contained in:
parent
8bdec18d58
commit
7323c65d53
|
@ -57,52 +57,50 @@ export default Component.extend({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.checkGroupName();
|
this.checkGroupNameDebounced();
|
||||||
|
|
||||||
return this._failedInputValidation(
|
return this._failedInputValidation(
|
||||||
I18n.t("admin.groups.new.name.checking")
|
I18n.t("admin.groups.new.name.checking")
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
checkGroupName() {
|
checkGroupNameDebounced() {
|
||||||
discourseDebounce(
|
discourseDebounce(this, this._checkGroupName, 500);
|
||||||
this,
|
},
|
||||||
function () {
|
|
||||||
if (isEmpty(this.nameInput)) {
|
_checkGroupName() {
|
||||||
return;
|
if (isEmpty(this.nameInput)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Group.checkName(this.nameInput)
|
||||||
|
.then((response) => {
|
||||||
|
const validationName = "uniqueNameValidation";
|
||||||
|
|
||||||
|
if (response.available) {
|
||||||
|
this.set(
|
||||||
|
validationName,
|
||||||
|
EmberObject.create({
|
||||||
|
ok: true,
|
||||||
|
reason: I18n.t("admin.groups.new.name.available"),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
this.set("disableSave", false);
|
||||||
|
this.set("model.name", this.nameInput);
|
||||||
|
} else {
|
||||||
|
let reason;
|
||||||
|
|
||||||
|
if (response.errors) {
|
||||||
|
reason = response.errors.join(" ");
|
||||||
|
} else {
|
||||||
|
reason = I18n.t("admin.groups.new.name.not_available");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set(validationName, this._failedInputValidation(reason));
|
||||||
}
|
}
|
||||||
|
})
|
||||||
Group.checkName(this.nameInput)
|
.catch(popupAjaxError);
|
||||||
.then((response) => {
|
|
||||||
const validationName = "uniqueNameValidation";
|
|
||||||
|
|
||||||
if (response.available) {
|
|
||||||
this.set(
|
|
||||||
validationName,
|
|
||||||
EmberObject.create({
|
|
||||||
ok: true,
|
|
||||||
reason: I18n.t("admin.groups.new.name.available"),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
this.set("disableSave", false);
|
|
||||||
this.set("model.name", this.nameInput);
|
|
||||||
} else {
|
|
||||||
let reason;
|
|
||||||
|
|
||||||
if (response.errors) {
|
|
||||||
reason = response.errors.join(" ");
|
|
||||||
} else {
|
|
||||||
reason = I18n.t("admin.groups.new.name.not_available");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set(validationName, this._failedInputValidation(reason));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(popupAjaxError);
|
|
||||||
},
|
|
||||||
500
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_failedInputValidation(reason) {
|
_failedInputValidation(reason) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user