mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user