Bug 28649 - Support for interactive validation of form elements
Summary: Support for interactive validation of form elements
Status: RESOLVED DUPLICATE of bug 164382
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P3 Enhancement
Assignee: Nobody
URL: http://www.whatwg.org/specs/web-apps/...
Keywords: InRadar
: 80419 136595 142817 158331 (view as bug list)
Depends on: 44436 95527 139552 27452 27959 28145 28868 31716 31718 34930 37345 40218 40429 40520 40747 48980 52430 52565 59019 60341
Blocks: HTML5Forms 163479
  Show dependency treegraph
 
Reported: 2009-08-21 17:53 PDT by Michelangelo De Simone
Modified: 2016-12-08 13:53 PST (History)
34 users (show)

See Also:


Attachments
Demo patch (21.45 KB, patch)
2009-09-02 02:43 PDT, Kent Tamura
tkent: review-
Details | Formatted Diff | Diff
Incomplete patch (rev.0) (20.87 KB, patch)
2009-10-06 00:06 PDT, Kent Tamura
abarth: review-
tkent: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michelangelo De Simone 2009-08-21 17:53:44 PDT
Support for interactive validation of form elements, HTML5 specs section 4.10.15.2, is necessary.
Comment 1 Michelangelo De Simone 2009-08-21 18:05:50 PDT
Some tip from other bugs this depends on:

1.
Form control elements can be in a "no-validate state" that is controlled by "novalidate" and "formNoValidate" attributes, plus some more condition. This snippet could be of help:

bool HTMLFormControlElement::isInNoValidateState() const
{
    return (isSuccessfulSubmitButton() && formNoValidate()) || m_form->novalidate();
}

2.
HTMLFormElement::checkValidity() needs to be adapted to deal with "unhandled invalid controls" (as per TODO comment). Actually it just iterates over form elements calling checkValidity() (that fires the invalid event, as per specs), but it must also return a list of invalid form controls that haven't been handled through the invalid event.
The following snippet might be of some help (was part of the proposed patch for bug 27452):

bool checkValidity(Vector<HTMLFormControlElement*>* unhandledInvalidControls = 0);

bool HTMLFormElement::checkValidity(Vector<HTMLFormControlElement*>* unhandledInvalidControls)
{
    Vector<HTMLFormControlElement*> invalidControls;

    for (unsigned i = 0; i < formElements.size(); ++i) {
        HTMLFormControlElement* control = formElements[i];
        if (control->willValidate() && !control->validity()->valid())
            invalidControls.append(control);
    }

    if (invalidControls.isEmpty())
        return true;

    for (unsigned n = 0; n < invalidControls.size(); ++n) {
        HTMLFormControlElement* invalidControl = invalidControls[n];
        bool eventCanceled = invalidControl->dispatchEvent(eventNames().invalidEvent, false, true);
        if (eventCanceled && unhandledInvalidControls)
            unhandledInvalidControls->append(invalidControl);
    }

    return false;
}
Comment 2 Kent Tamura 2009-08-28 01:38:14 PDT
I have started implementation.
Comment 3 Michelangelo De Simone 2009-08-28 04:02:37 PDT
(In reply to comment #2)

> I have started implementation.

Good! I think you'll be needing support for the validationMessage for interactive validation step 3 (4.10.15.2) [bug 27959], I'm gonna speed it up.
Comment 4 Kent Tamura 2009-08-28 06:59:15 PDT
> Good! I think you'll be needing support for the validationMessage for
> interactive validation step 3 (4.10.15.2) [bug 27959], I'm gonna speed it up.

That's right!  The implementation requires validationMessage().
Comment 5 Kent Tamura 2009-09-02 02:43:15 PDT
Created attachment 38918 [details]
Demo patch

A workable demo patch.  This is not ready to be reviewed.  It has no tests and it depends on bug#27959 and bug#28868.
Comment 6 Kent Tamura 2009-09-08 00:05:42 PDT
I'll use Balloon Tooltip for Windows to show validation messages.
  http://msdn.microsoft.com/en-us/library/bb760250(VS.85).aspx

I don't know if Mac OS has a corresponding control.
Comment 7 Kent Tamura 2009-10-06 00:06:46 PDT
Created attachment 40698 [details]
Incomplete patch (rev.0)

I'd like to ask comments on the patch though it is incomplete.
The patch will add the following behavior:
 - Show/hide a validation message when an invalid form control gets/losts the focus
  The way to show messages depends on each of platforms.
 - Prevent a form submission if the form has invalid controls

TODO:
 - Add tests
 - Build file changes for other platforms
 - Provide ChangeLog.
Comment 8 Adam Barth 2009-10-18 22:43:40 PDT
Comment on attachment 40698 [details]
Incomplete patch (rev.0)

As you say, the patch is incomplete.  No ChangeLog.  No tests.  If you'd like feedback on this patch, I recommend asking the relevant people on IRC or email.  Having this patch in the review queue just makes it harder to review complete patches.
Comment 9 Kent Tamura 2009-11-20 04:17:29 PST
I split this to 3 patches.  Bug#31716, Bug#31718 and this will have patches.
Comment 10 Alexey Proskuryakov 2010-06-25 13:50:40 PDT
I think that form validation should be disabled until:
- a solution is found for the compatibility problem with "required" attribute name;
- UI for correcting problems is implemented (as tracked by bug 31718/bug 40747). Currently the user experience is just horrible.
Comment 11 Brenton 2010-06-28 11:58:43 PDT
I agree with Alexey.  In 2008, I wrote an app to the HTML5 spec, then backported the validation API to JavaScript to support then-existing browsers.  I've seen the app break a couple of times due to changes in WebKit (which Tamura is always eager to fix).

If you go to http://beta.insightdining.com/surveys/limon/ without the WebKit validator, the page scrolls smoothly to take you to an invalid element on form submission.  Since the validation constraints have been added, the page abruptly jumps to the first invalid <input/>.  I'm sure there are users who don't understand what's going on when this happens.  For that matter, I wasn't even sure what was going on when I was debugging #40591.
Comment 12 Alexey Proskuryakov 2014-09-08 23:29:17 PDT
*** Bug 80419 has been marked as a duplicate of this bug. ***
Comment 13 Alexey Proskuryakov 2014-09-08 23:29:25 PDT
*** Bug 136595 has been marked as a duplicate of this bug. ***
Comment 14 Alexey Proskuryakov 2015-03-18 22:25:42 PDT
*** Bug 142817 has been marked as a duplicate of this bug. ***
Comment 15 Haralan Dobrev 2015-04-21 09:12:33 PDT
This ticket was created as an enhancement, but the last few tickets which were marked as duplicate to this are more critical. It seems this problem now affects normal validation and not only the JavaScript API.

IMHO the priority/importance of this ticket should be increased.
Comment 16 Darin Adler 2015-04-21 15:13:30 PDT
This always affected “normal validation”, not just JavaScript API, and that validation is a new feature, and one that is not implemented yet in WebKit.

I understand that you would like to see the feature!
Comment 17 Alexey Proskuryakov 2016-06-04 12:57:06 PDT
*** Bug 158331 has been marked as a duplicate of this bug. ***
Comment 18 Amanda 2016-09-30 14:56:12 PDT
Is anyone currently working on this?  It was submitted 7 years ago, and Safari is now the only browser whose current version will submit a form with invalid constraints.
Comment 19 Radar WebKit Bug Importer 2016-10-05 11:57:39 PDT
<rdar://problem/28636170>
Comment 20 Chris Dumez 2016-12-08 13:50:22 PST

*** This bug has been marked as a duplicate of bug 164382 ***
Comment 21 Chris Dumez 2016-12-08 13:53:58 PST
(In reply to comment #18)
> Is anyone currently working on this?  It was submitted 7 years ago, and
> Safari is now the only browser whose current version will submit a form with
> invalid constraints.

Safari Technology Preview 19 has this enabled:
https://webkit.org/blog/7093/release-notes-for-safari-technology-preview-19/