[FIX] web: domain selector dialog: disable confirm button on click
On confirmation of a domain created in the domain selector dialog, a validation check involving the server is done. That validation based on a search_count can be rather/too costly (see PR message). Since the search_count is done in silent mode and the confirmation button is not disabled on click, if the validation takes too much time, the user is lead to think that the first click did not work and clicks again, and so on... Here we disable the button on appropriate time to avoid that situation. Part-of: odoo/odoo#127832
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { _t } from "../l10n/translation";
|
||||
import { Component, useState } from "@odoo/owl";
|
||||
import { Component, useRef, useState } from "@odoo/owl";
|
||||
import { Dialog } from "../dialog/dialog";
|
||||
import { Domain } from "@web/core/domain";
|
||||
import { DomainSelector } from "../domain_selector/domain_selector";
|
||||
@@ -13,6 +13,7 @@ export class DomainSelectorDialog extends Component {
|
||||
this.orm = useService("orm");
|
||||
this.user = useService("user");
|
||||
this.state = useState({ domain: this.props.domain });
|
||||
this.confirmButtonRef = useRef("confirm");
|
||||
}
|
||||
|
||||
get confirmButtonText() {
|
||||
@@ -50,12 +51,16 @@ export class DomainSelectorDialog extends Component {
|
||||
}
|
||||
|
||||
async onConfirm() {
|
||||
this.confirmButtonRef.el.disabled = true;
|
||||
try {
|
||||
let domain = new Domain(this.state.domain);
|
||||
const evalContext = { ...this.user.context, ...this.props.context };
|
||||
domain = domain.toList(evalContext);
|
||||
await this.orm.silent.searchCount(this.props.resModel, domain, { limit: 1 });
|
||||
} catch {
|
||||
if (this.confirmButtonRef.el) {
|
||||
this.confirmButtonRef.el.disabled = false;
|
||||
}
|
||||
this.notification.add(this.env._t("Domain is invalid. Please correct it"), {
|
||||
type: "danger",
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<button class="btn btn-secondary" t-on-click="() => props.close()">Close</button>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<button class="btn btn-primary" t-att-disabled="disabled" t-on-click="onConfirm"><t t-esc="confirmButtonText"/></button>
|
||||
<button class="btn btn-primary" t-att-disabled="disabled" t-on-click="onConfirm" t-ref="confirm"><t t-esc="confirmButtonText"/></button>
|
||||
<button class="btn btn-secondary" t-on-click="onDiscard"><t t-esc="discardButtonText"/></button>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user