Check for disabled button in click handler

For some reason, even though jQuery UI dialogs know about their
own buttons, they don't know if the buttons are disabled. This
means that it's still possible to submit the dialog when a button
is disabled.

This change (which is mostly whitespace) adds a check in the click
handler to return early if the 'insert link' button is disabled.
It also gives this button a class name, and so simplifies the other
place that refers to the button.

Bug: T298596
Change-Id: I39fea13b1874f851a68cf08243b3e7ccd355d775
This commit is contained in:
Sam Wilson 2022-02-11 15:41:06 +08:00 committed by Derk-Jan Hartman
parent 5c9d867847
commit 64d5613172

View file

@ -120,10 +120,7 @@
* @param {boolean} enable Whether to enable or disable the button
*/
var setButtonState = function ( enable ) {
// eslint-disable-next-line no-jquery/no-sizzle
$( '.ui-dialog:visible .ui-dialog-buttonpane button' )
.first()
.button( 'option', 'disabled', !enable );
$( '.wikieditor-toolbar-tool-link-insert' ).button( 'option', 'disabled', !enable );
};
// Automatically copy the value of the internal link page title field to the link text field unless the
// user has changed the link text field - this is a convenience thing since most link texts are going to
@ -152,7 +149,10 @@
width: 500,
dialogClass: 'wikiEditor-toolbar-dialog',
buttons: {
'wikieditor-toolbar-tool-link-insert': function () {
'wikieditor-toolbar-tool-link-insert': {
class: 'wikieditor-toolbar-tool-link-insert',
text: mw.msg( 'wikieditor-toolbar-tool-link-insert' ),
click: function () {
var that = this;
function escapeInternalText( s ) {
@ -167,6 +167,11 @@
return s.replace( /(\]+)/g, '<nowiki>$1</nowiki>' );
}
// Make sure that this button isn't disabled.
if ( $( '.wikieditor-toolbar-tool-link-insert' ).button( 'option', 'disabled' ) ) {
return;
}
var target = insertLinkTitleInputField.getField().getValue();
var text = insertLinkLinkTextField.getField().getValue();
if ( text.trim() === '' ) {
@ -244,6 +249,7 @@
insertLinkTitleInputField.reset();
insertLinkLinkTextField.getField().setValue( '' );
insertLinkLinkTypeField.getField().selectItem( null );
}
},
'wikieditor-toolbar-tool-link-cancel': function () {
$( this ).dialog( 'close' );