Bug 942321 - Changing a select option field via javascript updates validity state. r=bz

This commit is contained in:
Giovanni Sferro 2014-05-06 19:19:00 +02:00
parent a4da8b744e
commit 8855692a5d
5 changed files with 62 additions and 1 deletions

View File

@ -243,6 +243,25 @@ HTMLOptionElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
return NS_OK;
}
nsresult
HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
if (aNameSpaceID == kNameSpaceID_None &&
aName == nsGkAtoms::value && Selected()) {
// Since this option is selected, changing value
// may have changed missing validity state of the
// Select element
HTMLSelectElement* select = GetSelect();
if (select) {
select->UpdateValueMissingValidityState();
}
}
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
aValue, aNotify);
}
NS_IMETHODIMP
HTMLOptionElement::GetText(nsAString& aText)
{

View File

@ -51,6 +51,8 @@ public:
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify) MOZ_OVERRIDE;
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify) MOZ_OVERRIDE;
void SetSelectedInternal(bool aValue, bool aNotify);

View File

@ -395,6 +395,7 @@ public:
nsresult GetValidationMessage(nsAString& aValidationMessage,
ValidityStateType aType) MOZ_OVERRIDE;
void UpdateValueMissingValidityState();
/**
* Insert aElement before the node given by aBefore
*/
@ -511,7 +512,6 @@ protected:
// nsIConstraintValidation
void UpdateBarredFromConstraintValidation();
bool IsValueMissing();
void UpdateValueMissingValidityState();
/**
* Find out how deep this content is from the select (1=direct child)

View File

@ -74,6 +74,7 @@ skip-if = e10s
[test_restore_form_elements.html]
[test_save_restore_radio_groups.html]
[test_select_selectedOptions.html]
[test_select_validation.html]
[test_set_range_text.html]
[test_step_attribute.html]
skip-if = e10s

View File

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=942321
-->
<head>
<title>Test for Bug 942321</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=942321">Mozilla Bug 942321</a>
<p id="display"></p>
<form id="form" href="">
<select required id="testselect">
<option id="placeholder" value="" selected>placeholder</option>
<option value="test" id="actualvalue">test</option>
<select>
<input type="submit" />
</form>
<script class="testbody" type="text/javascript">
/** Test for Bug 942321 **/
var option = document.getElementById("actualvalue");
option.selected = true;
is(form.checkValidity(), true, "Select is required and should be valid");
var placeholder = document.getElementById("placeholder");
placeholder.selected = true;
is(form.checkValidity(), false, "Select is required and should be invalid");
placeholder.value = "not-invalid-anymore";
is(form.checkValidity(), true, "Select is required and should be valid when option's value is changed by javascript");
</script>
</pre>
</body>
</html>