зеркало из https://github.com/mozilla/gecko-dev.git
Bug 556013 - Implement novalidate attribute for form elements. r=smaug a2.0=blocking
This commit is contained in:
Родитель
03059b169a
Коммит
bb317945aa
|
@ -601,6 +601,7 @@ GK_ATOM(normal, "normal")
|
|||
GK_ATOM(normalizeSpace, "normalize-space")
|
||||
GK_ATOM(noscript, "noscript")
|
||||
GK_ATOM(noshade, "noshade")
|
||||
GK_ATOM(novalidate, "novalidate")
|
||||
GK_ATOM(_not, "not")
|
||||
GK_ATOM(nowrap, "nowrap")
|
||||
GK_ATOM(number, "number")
|
||||
|
|
|
@ -507,6 +507,7 @@ nsHTMLButtonElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
// Using presShell to dispatch the event. It makes sure that
|
||||
// event is not handled if the window is being destroyed.
|
||||
if (presShell && (event.message != NS_FORM_SUBMIT ||
|
||||
mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate) ||
|
||||
mForm->CheckValidFormSubmission())) {
|
||||
// TODO: removing this code and have the submit event sent by the form
|
||||
// see bug 592124.
|
||||
|
|
|
@ -369,6 +369,7 @@ NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLFormElement, Enctype, enctype,
|
|||
kFormDefaultEnctype->tag)
|
||||
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLFormElement, Method, method,
|
||||
kFormDefaultMethod->tag)
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLFormElement, NoValidate, novalidate)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLFormElement, Name, name)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLFormElement, Target, target)
|
||||
|
||||
|
@ -1662,6 +1663,9 @@ nsHTMLFormElement::CheckValidFormSubmission()
|
|||
* invalid. See bug 587671.
|
||||
*/
|
||||
|
||||
NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
|
||||
"We shouldn't be there if novalidate is set!");
|
||||
|
||||
// When .submit() is called aEvent = nsnull so we can rely on that to know if
|
||||
// we have to check the validity of the form.
|
||||
nsCOMPtr<nsIObserverService> service =
|
||||
|
|
|
@ -278,6 +278,7 @@ public:
|
|||
*
|
||||
* @return Whether the form is valid.
|
||||
*
|
||||
* @note Do not call this method if novalidate/formnovalidate is used.
|
||||
* @note This method might disappear with bug 592124, hopefuly.
|
||||
*/
|
||||
bool CheckValidFormSubmission();
|
||||
|
|
|
@ -1640,7 +1640,9 @@ nsHTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext)
|
|||
nsMouseEvent event(PR_TRUE, NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal);
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
shell->HandleDOMEventWithTarget(submitContent, &event, &status);
|
||||
} else if (mForm->HasSingleTextControl() && mForm->CheckValidFormSubmission()) {
|
||||
} else if (mForm->HasSingleTextControl() &&
|
||||
(mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate) ||
|
||||
mForm->CheckValidFormSubmission())) {
|
||||
// TODO: removing this code and have the submit event sent by the form,
|
||||
// bug 592124.
|
||||
// If there's only one text control, just submit the form
|
||||
|
@ -2433,6 +2435,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
// TODO: removing this code and have the submit event sent by the
|
||||
// form, see bug 592124.
|
||||
if (presShell && (event.message != NS_FORM_SUBMIT ||
|
||||
mForm->HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate) ||
|
||||
mForm->CheckValidFormSubmission())) {
|
||||
// Hold a strong ref while dispatching
|
||||
nsRefPtr<nsHTMLFormElement> form(mForm);
|
||||
|
|
|
@ -219,6 +219,7 @@ _TEST_FILES = \
|
|||
583288_redirect_server.sjs \
|
||||
test_bug555840.html \
|
||||
test_bug561636.html \
|
||||
test_bug556013.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=556013
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 556013</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/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=556013">Mozilla Bug 556013</a>
|
||||
<p id="display"></p>
|
||||
<iframe style='width:50px; height: 50px;' name='t'></iframe>
|
||||
<div id="content">
|
||||
<form target='t' action='data:text/html,' novalidate>
|
||||
<input id='av' required>
|
||||
<input id='a' type='submit'>
|
||||
</form>
|
||||
<form target='t' action='data:text/html,' novalidate>
|
||||
<input id='bv' type='checkbox' required>
|
||||
<button id='b' type='submit'></button>
|
||||
</form>
|
||||
<form target='t' action='data:text/html,' novalidate>
|
||||
<input id='c' required>
|
||||
</form>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 556013 **/
|
||||
|
||||
var form = document.createElement('form');
|
||||
|
||||
function checkNoValidateAttribute(aForm)
|
||||
{
|
||||
ok("noValidate" in form, "noValidate should be a form element IDL attribute");
|
||||
|
||||
ok(!aForm.noValidate, "aForm novalidate attribute should be disabled");
|
||||
is(aForm.getAttribute('novalidate'), null,
|
||||
"aForm novalidate attribute should be disabled");
|
||||
|
||||
aForm.noValidate = true;
|
||||
ok(aForm.noValidate, "aForm novalidate attribute should be enabled");
|
||||
isnot(aForm.getAttribute('novalidate'), null,
|
||||
"aForm novalidate attribute should be enabled");
|
||||
|
||||
aForm.removeAttribute('novalidate');
|
||||
aForm.setAttribute('novalidate', '');
|
||||
ok(aForm.noValidate, "aForm novalidate attribute should be enabled");
|
||||
isnot(aForm.getAttribute('novalidate'), null,
|
||||
"aForm novalidate attribute should be enabled");
|
||||
|
||||
aForm.removeAttribute('novalidate');
|
||||
ok(!aForm.noValidate, "aForm novalidate attribute should be disabled");
|
||||
is(aForm.getAttribute('novalidate'), null,
|
||||
"aForm novalidate attribute should be disabled");
|
||||
}
|
||||
|
||||
checkNoValidateAttribute(form);
|
||||
|
||||
/**
|
||||
* novalidate should prevent form validation, thus not blocking form submission.
|
||||
*
|
||||
* NOTE: if there is no invalidformsubmit observer, the form submission will
|
||||
* never be blocked and this test might be a false-positive but that should not
|
||||
* be a problem.
|
||||
*/
|
||||
document.forms[0].addEventListener("submit", function(aEvent) {
|
||||
aEvent.target.removeEventListener("submit", arguments.callee, false);
|
||||
ok(true, "novalidate has been correctly used for first form");
|
||||
document.getElementById('b').click();
|
||||
}, false);
|
||||
|
||||
document.forms[1].addEventListener("submit", function(aEvent) {
|
||||
aEvent.target.removeEventListener("submit", arguments.callee, false);
|
||||
ok(true, "novalidate has been correctly used for second form");
|
||||
var c = document.getElementById('c');
|
||||
c.focus(); synthesizeKey("VK_RETURN", {type: "keypress"});
|
||||
}, false);
|
||||
|
||||
document.forms[2].addEventListener("submit", function(aEvent) {
|
||||
aEvent.target.removeEventListener("submit", arguments.callee, false);
|
||||
ok(true, "novalidate has been correctly used for third form");
|
||||
SimpleTest.executeSoon(SimpleTest.finish);
|
||||
}, false);
|
||||
|
||||
/**
|
||||
* We have to be sure invalid events are not send too.
|
||||
* They should be sent before the submit event so we can just create a test
|
||||
* failure if we got one. All of them should be catched if sent.
|
||||
* At worst, we got random green which isn't harmful.
|
||||
*/
|
||||
function invalidHandling(aEvent)
|
||||
{
|
||||
aEvent.target.removeEventListener("invalid", invalidHandling, false);
|
||||
ok(false, "invalid event should not be sent");
|
||||
}
|
||||
|
||||
document.getElementById('av').addEventListener("invalid", invalidHandling, false);
|
||||
document.getElementById('bv').addEventListener("invalid", invalidHandling, false);
|
||||
document.getElementById('c').addEventListener("invalid", invalidHandling, false);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// This is going to call all the tests (with a chain reaction).
|
||||
SimpleTest.waitForFocus(function() {
|
||||
document.getElementById('a').click();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -47,17 +47,20 @@
|
|||
* http://www.w3.org/TR/DOM-Level-2-HTML/
|
||||
*/
|
||||
|
||||
[scriptable, uuid(083d2e20-a996-11df-94e2-0800200c9a66)]
|
||||
[scriptable, uuid(48db9517-3a85-4f6d-af5f-106ce6aadd7d)]
|
||||
interface nsIDOMHTMLFormElement : nsIDOMHTMLElement
|
||||
{
|
||||
readonly attribute nsIDOMHTMLCollection elements;
|
||||
readonly attribute long length;
|
||||
attribute DOMString name;
|
||||
attribute DOMString acceptCharset;
|
||||
attribute DOMString action;
|
||||
attribute DOMString enctype;
|
||||
attribute DOMString method;
|
||||
attribute DOMString target;
|
||||
attribute boolean noValidate;
|
||||
|
||||
readonly attribute nsIDOMHTMLCollection elements;
|
||||
readonly attribute long length;
|
||||
|
||||
void submit();
|
||||
void reset();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче