VE integration: Fix the "Refresh" button

Previously, clicking it would change the image, but the widget would
still expect the user to fill in the original CAPTCHA.

Change-Id: I24a963e760951427f6d233302429c1baf1fb299f
This commit is contained in:
Bartosz Dziewoński 2020-03-24 01:07:00 +01:00
parent da4c75e387
commit 601b1fff84
2 changed files with 6 additions and 1 deletions

View file

@ -22,6 +22,9 @@ $( document ).on( 'click', '.fancycaptcha-reload', function () {
// now do the same with a selector that works for pre-1.27 login forms
$root.find( '[name="wpCaptchaId"]' ).val( captchaIndex );
$root.find( '[name="wpCaptchaWord"]' ).val( '' ).trigger( 'focus' );
// and make it accessible for other tools, e.g. VisualEditor
$captchaImage.data( 'captchaId', captchaIndex );
}
} )
.always( function () {

View file

@ -44,7 +44,8 @@ mw.libs.ve.targetLoader.addPlugin( function () {
// Register extra fields
target.saveFields.wpCaptchaId = function () {
return captchaData.id;
// 'ext.confirmEdit.fancyCaptcha' can update this value if the "Refresh" button is used
return $captchaImg ? $captchaImg.data( 'captchaId' ) : captchaData.id;
};
target.saveFields.wpCaptchaWord = function () {
return captchaInput.getValue();
@ -71,6 +72,7 @@ mw.libs.ve.targetLoader.addPlugin( function () {
$captchaParagraph.append( mw.message( 'fancycaptcha-edit' ).parseDom() );
$captchaImg = $( '<img>' )
.attr( 'src', captchaData.url )
.data( 'captchaId', captchaData.id )
.addClass( 'fancycaptcha-image' )
.on( 'load', onCaptchaLoad );
$captchaDiv.append(