2 * JavaScript for change credentials form.
5 mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
6 const api = new mw.Api();
8 $root.find( '.mw-changecredentials-validate-password.oo-ui-fieldLayout' ).each( function () {
9 const self = OO.ui.FieldLayout.static.infuse( $( this ) );
11 let currentApiPromise;
12 self.getField().setValidation( ( passwordValue ) => {
13 if ( currentApiPromise ) {
14 currentApiPromise.abort();
15 currentApiPromise = undefined;
18 passwordValue = passwordValue.trim();
20 if ( passwordValue === '' ) {
25 const d = $.Deferred();
26 currentApiPromise = api.post( {
27 action: 'validatepassword',
28 password: passwordValue,
32 uselang: mw.config.get( 'wgUserLanguage' )
33 } ).done( ( resp ) => {
34 const pwinfo = resp.validatepassword,
35 good = pwinfo.validity === 'Good';
37 currentApiPromise = undefined;
41 errors = pwinfo.validitymessages.map( ( m ) => new OO.ui.HtmlSnippet( m.html ) );
43 self.setErrors( errors || [] );
47 return d.promise( { abort: currentApiPromise.abort } );