Account for sanitization changes properly in InputWidget

setValue() doesn't do anything if this.value === value, but with
sanitization it's possible for that to be true while the value in
the DOM is out of sync and needs to be changed.

The fix is to check for this.value changing and the DOM changing
separately.

Change-Id: I5f571445f5729f5477902c155a4ee9588b7194a8
This commit is contained in:
Rob Moen 2013-11-19 13:24:44 +05:30 committed by Catrope
parent ef5f3ec054
commit f496085017

View file

@ -114,16 +114,16 @@ OO.ui.InputWidget.prototype.setRTL = function ( isRTL ) {
* @chainable
*/
OO.ui.InputWidget.prototype.setValue = function ( value ) {
var domValue = this.$input.val();
value = this.sanitizeValue( value );
if ( this.value !== value ) {
this.value = value;
// Only update the DOM if we must
if ( domValue !== this.value ) {
this.$input.val( value );
}
this.emit( 'change', this.value );
}
// Update the DOM if it has changed. Note that with sanitizeValue, it
// is possible for the DOM value to change without this.value changing.
if ( this.$input.val() !== this.value ) {
this.$input.val( this.value );
}
return this;
};