Bug 787102 - (1/2) - Dispatch the change event for input elements even if .value is set while focused. r=bz

This commit is contained in:
Mounir Lamouri 2012-09-05 13:39:33 +01:00
Родитель 83b5dc5b17
Коммит 70056ac224
2 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -1060,9 +1060,24 @@ nsHTMLInputElement::SetValue(const nsAString& aValue)
}
}
else {
SetValueInternal(aValue, false, true);
if (IsSingleLineTextControl(false)) {
GetValueInternal(mFocusedValue);
// If the value has been set by a script, we basically want to keep the
// current change event state. If the element is ready to fire a change
// event, we should keep it that way. Otherwise, we should make sure the
// element will not fire any event because of the script interaction.
//
// NOTE: this is currently quite expensive work (too much string
// manipulation). We should probably optimize that.
nsAutoString currentValue;
GetValueInternal(currentValue);
SetValueInternal(aValue, false, true);
if (mFocusedValue.Equals(currentValue)) {
GetValueInternal(mFocusedValue);
}
} else {
SetValueInternal(aValue, false, true);
}
}

Просмотреть файл

@ -106,6 +106,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
input.blur();
is(textInputChange[0], 2, "text input element should have dispatched change event (2).");
// value being set while focused
input.focus();
input.value = 'foo';
input.blur();
is(textInputChange[0], 2, "text input element should not have dispatched change event (2).");
// value being set while focused after being modified manually
input.focus();
synthesizeKey("f", {});
input.value = 'bar';
input.blur();
is(textInputChange[0], 3, "text input element should not have dispatched change event (3).");
//focus and blur textarea
var textarea = document.getElementById("textarea");
textarea.focus();