Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML5 Form Validation - Subsequent Steps #10843

Closed
wants to merge 1 commit into from
Closed

Conversation

@vinay92
Copy link

vinay92 commented Apr 26, 2016

Implemented the subsequent steps mentioned in the spec.


This change is Reviewable

@highfive
Copy link

highfive commented Apr 26, 2016

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @mbrubeck (or someone else) soon.

@highfive
Copy link

highfive commented Apr 26, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/htmltextareaelement.rs, components/script/dom/htmlbuttonelement.rs, components/script/dom/validitystate.rs, components/script/dom/validation.rs, components/script/dom/htmlformelement.rs, components/script/dom/htmlselectelement.rs, components/script/dom/htmlinputelement.rs, components/script/dom/htmlobjectelement.rs
@highfive
Copy link

highfive commented Apr 26, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@KiChjang
Copy link
Member

KiChjang commented Apr 26, 2016

Review status: 0 of 8 files reviewed at latest revision, 1 unresolved discussion.


components/script/dom/htmlformelement.rs, line 812 [r1] (raw file):
I'm quite sad that nobody realized that I left a comment here that makes life easier when implementing form validations for form control elements.


Comments from Reviewable

@srm09
Copy link
Contributor

srm09 commented Apr 26, 2016

Review status: 0 of 8 files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/htmlformelement.rs, line 377 [r1] (raw file):
Follow snake casing (check_validity) for function and variable names


Comments from Reviewable

@jdm
Copy link
Member

jdm commented Apr 26, 2016

r? @KiChjang
Please reassign if you don't have time :)

@highfive highfive assigned KiChjang and unassigned mbrubeck Apr 26, 2016
@KiChjang
Copy link
Member

KiChjang commented Apr 26, 2016

-S-awaiting-review +S-needs-code-changes

As I've noted previously, we really should make the best use of the existing FormControl infrastructure, this would save you a lot of headaches :). Most of my comments revolve around how exactly we should be utilizing it. Don't hesitate to ask questions if it's still unclear!


Reviewed 6 of 8 files at r1, 3 of 24 files at r4, 1 of 1 files at r6, 1 of 1 files at r7.
Review status: all files reviewed at latest revision, 17 unresolved discussions.


components/script/dom/htmlformelement.rs, line 358 [r1] (raw file):
What we should do instead is to upcast err[0] into an HTMLElement, and then call .Focus(). I'm also not sure whether this is necessary. @jdm or @Ms2ger, should the first invalid form element request focus on itself?


components/script/dom/htmlformelement.rs, line 367 [r1] (raw file):
This also isn't how I imagine the check for validation candidate should be implemented. As I've noted further down in this file, we can just add member methods on implementors of FormControl.


components/script/dom/htmlformelement.rs, line 377 [r1] (raw file):
This shouldn't be implemented here; this is part of the constraint validation API, which should live under impl HTMLFormElementMethods for HTMLFormElement.


components/script/dom/htmlformelement.rs, line 386 [r1] (raw file):
Ditto about being under impl HTMLFormElementMethods for HTMLFormElement.


components/script/dom/htmlformelement.rs, line 393 [r1] (raw file):
Ditto about member methods on implementors of FormControl.


components/script/dom/htmlformelement.rs, line 442 [r1] (raw file):
nit: Ending brace on newline.


components/script/dom/htmlinputelement.rs, line 903 [r1] (raw file):
It doesn't sound quite right that the form element requests focus on the first errored element, only then to have all other invalid elements to request focus as well. I'd like to see the spec for this.


components/script/dom/htmlselectelement.rs, line 237 [r6] (raw file):
Where is this being called?


components/script/dom/htmltextareaelement.rs, line 373 [r1] (raw file):
Spec for this behaviour, please.


components/script/dom/validation.rs, line 8 [r1] (raw file):
I'm actually not convinced that this trait (or this file for the matter) should exist. Following on my coment with FormControls, it seems unnecessary to add another trait which all FormControls should implement.


components/script/dom/validitystate.rs, line 47 [r7] (raw file):
Revert this and add that newline back, please.


components/script/dom/validitystate.rs, line 74 [r7] (raw file):
I'm not convinced that this is the optimal way of handling form control validity. The code here is divorced from the actual elements that implements the constraint validation API. I propose to add value_missing, type_mismatch and other methods to the FormControl trait, and in here, downcast self.element to FormControl and call the methods appropriately.


components/script/dom/validitystate.rs, line 649 [r7] (raw file):
nit: Wrong indentation and space before |.


components/compositing/compositor.rs, line 1308 [r4] (raw file):
This seems unrelated to your changes, an error from rebasing?


components/compositing/constellation.rs, line 890 [r4] (raw file):
Same for this file. Error from rebasing?


components/gfx/font_cache_thread.rs, line 173 [r4] (raw file):
Same for this file. Error from rebasing?


Comments from Reviewable

@KiChjang
Copy link
Member

KiChjang commented Apr 29, 2016

@vinay92 Is this ready for review? If not, just ping me whenever you want me to look at it.

@vinay92
Copy link
Author

vinay92 commented Apr 29, 2016

Hey Keith,

We are currently working on the changes you mentioned. We have an exam
tomorrow, once that is done, we will incorporate the remaining changes you
mentioned and ping you when it is ready for review.

Thank You,
Vinay.

On Thu, Apr 28, 2016 at 8:44 PM, Keith Yeung notifications@github.com
wrote:

@vinay92 https://github.com/vinay92 Is this ready for review? If not,
just ping me whenever you want me to look at it.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#10843 (comment)

@bors-servo
Copy link
Contributor

bors-servo commented Apr 29, 2016

The latest upstream changes (presumably #10895) made this pull request unmergeable. Please resolve the merge conflicts.

@srm09 srm09 force-pushed the vinay92:h5fv branch from b250bda to 85233c3 May 2, 2016
@srm09 srm09 force-pushed the vinay92:h5fv branch 2 times, most recently from cbe0d02 to 3d373ff May 2, 2016
@srm09
Copy link
Contributor

srm09 commented May 2, 2016

Fixed errors while rebasing. No new code changes committed. Please do not review.

@raviflipsyde
Copy link

raviflipsyde commented May 3, 2016

Hi @KiChjang ,
I am trying to fix the focus issue, when there is one or more invalid form element - user agent needs to focus on one of them. (spec: https://html.spec.whatwg.org/multipage/forms.html#interactively-validate-the-constraints)
as u advised, I've upcasted err[0] into an HTMLElement, and then call .Focus() on it.
The order in which the elements are getting focused is not in order though.

@KiChjang
Copy link
Member

KiChjang commented May 3, 2016

@raviflipsyde Is it because other invalid form elements are requesting focus as well? I had concerns about that in my review. Take a look at htmlinputelement.rs for example, it is requesting for focus when an "invalid" event is fired, causing it to conflict with your changes.

@raviflipsyde
Copy link

raviflipsyde commented May 3, 2016

I guess that needs to be removed from there.

@highfive
Copy link

highfive commented May 3, 2016

New code was committed to pull request.

2 similar comments
@highfive
Copy link

highfive commented May 3, 2016

New code was committed to pull request.

@highfive
Copy link

highfive commented May 3, 2016

New code was committed to pull request.

Fixed the compilation issues in h5fv. Still need to incorporate the other half of keith's recommended changes

Moved the code to include check and report validity to webidl file

Fixed focus issue in htmlformelement, removed warning code

Fixed tidy-test issues

moved the validation logic from validity state to individual form elements ike inputelement, selectelement
@vinay92 vinay92 force-pushed the vinay92:h5fv branch from 79f600e to 3ed6e7f May 4, 2016
@highfive
Copy link

highfive commented May 4, 2016

New code was committed to pull request.

@vinay92
Copy link
Author

vinay92 commented May 4, 2016

@KiChjang We have made the changes you mentioned in the review. The branch is now ready for review. Thanks.

@KiChjang
Copy link
Member

KiChjang commented May 8, 2016

I don't think I have time for reviewing this in the near future. r? @jdm

@highfive highfive assigned jdm and unassigned KiChjang May 8, 2016
@bors-servo
Copy link
Contributor

bors-servo commented May 12, 2016

The latest upstream changes (presumably #10714) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented May 26, 2016

I have the following concerns about this pull request:

  • there is a lot of duplicated code (such as candidate_for_validation and satisfies_constraints)
  • the mechanism of splitting each possible constraint into a separate function yields a lot of stub methods that just return false; it might make more sense to have a single method that returns a bit flags that represent failed constraints.
  • there are several places that downcast to a particular element type and call the same sets of methods for each one - this would be better handled by obtaining a trait object and invoking the methods on that instead (like how as_maybe_activatable is used)
  • we probably don't want to use regular expressions for the number, email, and URL input types since there are a lot of edge cases possible
  • many of the validation methods could benefit from sharing common code (eg. TooShort, RangeUnderflow, RangeOverflow in HTMLInputElement)
  • there are a number of instances where we parse strings as numbers and unwrap the result, which will panic for non-numeric values
  • I'm not sure why the handle_event method is added for HTMLSelectElement

@KiChjang may have other more general architectural concerns. I'm closing this PR because I suspect that the original authors are not planning to continue working on it; if that assumption is untrue, they are welcome to do so and address the aforementioned concerns! I'm linking to this work from #11444 as the basis for any future implementation of the form validation.

@jdm jdm closed this May 26, 2016
@jdm
Copy link
Member

jdm commented May 26, 2016

That being said - thank you for doing this work and sharing your efforts! This will help us make better decisions when the time comes for someone else to finish your work.

@gpoesia gpoesia mentioned this pull request Jul 11, 2017
3 of 11 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants
You can’t perform that action at this time.