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

This commit is contained in:
Mounir Lamouri 2012-09-05 13:40:13 +01:00
parent 22a7f92553
commit 45c66f71d7
2 changed files with 29 additions and 2 deletions

View File

@ -545,8 +545,22 @@ nsHTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
NS_IMETHODIMP
nsHTMLTextAreaElement::SetValue(const nsAString& aValue)
{
// 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, true);
SetValueInternal(aValue, false);
GetValueInternal(mFocusedValue, true);
if (mFocusedValue.Equals(currentValue)) {
GetValueInternal(mFocusedValue, true);
}
return NS_OK;
}

View File

@ -117,7 +117,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
synthesizeKey("f", {});
input.value = 'bar';
input.blur();
is(textInputChange[0], 3, "text input element should not have dispatched change event (3).");
is(textInputChange[0], 3, "text input element should have dispatched change event (3).");
//focus and blur textarea
var textarea = document.getElementById("textarea");
@ -126,6 +126,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
textarea.blur();
is(textareaChange, 1, "Textarea element should have dispatched change event.");
// value being set while focused
textarea.focus();
textarea.value = 'foo';
textarea.blur();
is(textareaChange, 1, "textarea should not have dispatched change event (1).");
// value being set while focused after being modified manually
textarea.focus();
synthesizeKey("f", {});
textarea.value = 'bar';
textarea.blur();
is(textareaChange, 2, "textearea should have dispatched change event (2).");
//Non-text input tests:
for (var i = 0; i < NonTextInputTypes.length; ++i) {
//button, submit, image and reset input type tests.