dialog_widget: Add a new optional parameter validate_input.

This commit extends dialog_widget class by adding a new
optional paramter validate_input which will be a function
to validate the inputs in the dialog and will be called
before showing the spinner and calling the on_click function.

Currently, the password change modal uses this paramter to
validate that the old and new password inputs must not be
empty. Since the spinner will not be initiated in the case
where form is invalid, we need not hide the spinner after
showing the error and thus we can simplify the code to use
ui_report.error to show the error messages of empty fields.
This commit is contained in:
Sahil Batra
2021-11-29 23:12:33 +05:30
committed by Tim Abbott
parent 35f9ed6ebe
commit c20f5a9866
2 changed files with 32 additions and 16 deletions

View File

@@ -81,6 +81,7 @@ export function launch(conf) {
// * id: Custom id to the container element to modify styles.
// * single_footer_button: If true, don't include the "Cancel" button.
// * form_id: Id of the form element in the modal if it exists.
// * validate_input: Function to validate the input of the modal.
// * on_show: Callback to run when the modal is triggered to show.
// * on_shown: Callback to run when the modal is shown.
// * on_hide: Callback to run when the modal is triggered to hide.
@@ -125,6 +126,9 @@ export function launch(conf) {
// Set up handlers.
submit_button.on("click", (e) => {
if (conf.validate_input && !conf.validate_input(e)) {
return;
}
if (conf.loading_spinner) {
show_dialog_spinner();
} else if (conf.close_on_submit) {