JS: Removing trailing dots from a string

Met with this bug https://bugzilla.wikimedia.org/71704 in the UploadWizard extension last day, which was to make sure that the file name string do not contain dots or whitespace as that can cause trouble later. Thanks to Mark Traucer ( Wikimedia ), we got a wonderful solution for the same.

Remove trailing dots from a string foo.

cleanedFoo = $.trim( foo.replace( /\.+$/g, '' ) );

That would remove ‘n’ number of dots trailing in string foo
My personal solution to this was a bit more easy, but would work with only one trailing dot:

if ( foo.slice( -1 ) === '.' ) {
        cleanedFoo = foo.slice( 0, -1 );

The change is in gerrit : https://gerrit.wikimedia.org/r/#/c/169326/. 🙂
Happy Hacking !!

Greying out submit button untill user give input : jQuery snippets #1

The submit button needs to wait till the user enter something into the input box. This is useful in most cases, where null injection can cause trouble

* The button should initially become disabled
* It should become alright after the user enters some stuff
* It should go back to disabled state once the user have cleared everything out


$( ‘#buttonClick’ ).prop( ‘disabled’, true );
$(‘.input’).on(‘input’, function() {
$(this).next().prop(‘disabled’, $(this).val().length < 1);

Hope it helps someone.

Related links:-
[1] http://jsfiddle.net/4gxuU/
[2] https://gerrit.wikimedia.org/r/#/c/120487/