Prefer .text(); ensure button doesn't remain disabled due to invalid username after user changes the <select> option

This commit is contained in:
Theopolisme 2015-02-24 17:52:41 -06:00
parent 945f210277
commit 08f30134da

View File

@ -1762,10 +1762,28 @@
loadView( 'submit', { loadView( 'submit', {
customSubmitters: customSubmitters customSubmitters: customSubmitters
}, function () { }, function () {
// Reset the status indicators for the username & errors
function resetStatus () {
$afch.find( '#submitterName' ).removeClass( 'bad-input' );
$afch.find( '#submitterNameStatus' ).text( '' );
$afch.find( '#afchSubmitForm' )
.removeClass( 'disabled' )
.text( 'Submit' );
}
// Show the other textbox when `other` is selected in the menu // Show the other textbox when `other` is selected in the menu
$afch.find( '#submitType' ).change( function () { $afch.find( '#submitType' ).change( function () {
var isOtherSelected = $afch.find( '#submitType' ).val() === 'other'; var isOtherSelected = $afch.find( '#submitType' ).val() === 'other';
$afch.find( '#submitterNameWrapper' ).toggleClass( 'hidden', !isOtherSelected );
if ( isOtherSelected ) {
$afch.find( '#submitterNameWrapper' ).removeClass( 'hidden' );
$afch.find( '#submitterName' ).trigger( 'keyup' );
} else {
$afch.find( '#submitterNameWrapper' ).addClass( 'hidden' );
}
resetStatus();
// Show an error if there's no such user // Show an error if there's no such user
$afch.find( '#submitterName' ).keyup( function () { $afch.find( '#submitterName' ).keyup( function () {
@ -1775,11 +1793,7 @@
submitter = field.val(); submitter = field.val();
// Reset form // Reset form
field.removeClass( 'bad-input' ); resetStatus();
status.text( '' );
submitButton
.removeClass( 'disabled' )
.text( 'Submit' );
// If there's no value, don't even try // If there's no value, don't even try
if ( !submitter || !isOtherSelected ) { if ( !submitter || !isOtherSelected ) {
@ -1789,7 +1803,7 @@
// Check if the user string starts with "User:", because Template:AFC submission dies horribly if it does // Check if the user string starts with "User:", because Template:AFC submission dies horribly if it does
if ( submitter.lastIndexOf( 'User:', 0 ) === 0 ) { if ( submitter.lastIndexOf( 'User:', 0 ) === 0 ) {
field.addClass( 'bad-input' ); field.addClass( 'bad-input' );
status.html('Remove "User:" from the beginning.'); status.text( 'Remove "User:" from the beginning.' );
submitButton submitButton
.addClass( 'disabled' ) .addClass( 'disabled' )
.text( 'Invalid user name' ); .text( 'Invalid user name' );
@ -1804,16 +1818,13 @@
} ).done( function ( data ) { } ).done( function ( data ) {
if ( data.query.users[0].missing !== undefined ) { if ( data.query.users[0].missing !== undefined ) {
field.addClass( 'bad-input' ); field.addClass( 'bad-input' );
status.html('No user named "' + submitter + '".'); status.text( 'No user named "' + submitter + '".' );
submitButton submitButton
.addClass( 'disabled' ) .addClass( 'disabled' )
.text( 'No such user' ); .text( 'No such user' );
} }
} ); } );
} ); } );
// Trigger key handler
$afch.find( '#submitterName' ).trigger( 'keyup' );
} ); } );
} ); } );