Form validation student project
Josh Matthews edited this page Nov 21, 2016
·
9 revisions
Background information: The HTML5 specification defines a mechanism by which website authors can require browsers to validate the contents of forms before the user is allowed to submit them. Servo currently implements support for a subset of the form element types defined by the specification; this project is intended to implement the client-side validations steps and extend the supported subset to include additional form elements that support validation.
Initial steps:
- compile Servo and ensure that it runs on
tests/html/about-mozilla.html
- email the mozilla.dev.servo mailing list (be sure to subscribe first!) introducing your group and asking any necessary questions
- uncomment the attributes in
ValidityState.webidl
and fix the resulting build errors by implementing appropriate stub methods invaliditystate.rs
- make the
ValidityState
constructor take an&Element
argument and store it as aJS<Element>
member inValidityState
- add a new bitflag type that represents each possible validity check in
ValidityState
- define a
Validatable
trait that contains a method which accepts this bitflag as an argument (see theActivatable
trait for inspiration) - implement this trait for the form element types (
HTMLInputElement
,HTMLSelectElement
,HTMLButtonElement
, etc.), and define anas_maybe_validatable
method onElement
which returns an&Validatable
value if the element implements the trait (seeas_maybe_activatable
for inspiration) - Use the newly-added
JS<Element>
member to call these new methods as appropriate in each of the stub methods inValidityState
Subsequent steps:
- Fill out HTMLFormElement::static_validation such that it implements the steps to statically validate the constraints of a form element
- Add reporting code to
HTMLFormElement::interactive_validation
that prints out problems with the form to the console usingprintln!
, and focus the first element that does not validate. - Implement several validation states:
- the minimum and maximum length constraints based on the
minlength
/maxlength
members ofHTMLInputElement
- the missing constraint, using
Element::has_attribute
to determine if therequired
attribute is present
- the minimum and maximum length constraints based on the
- Implement the checkValidity and reportValidity APIs for
HTMLFormElement
(see the guide for adding new methods based on web specifications)