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

support form reset #584

Open
wkeese opened this issue Aug 27, 2015 · 2 comments
Open

support form reset #584

wkeese opened this issue Aug 27, 2015 · 2 comments

Comments

@wkeese
Copy link
Member

wkeese commented Aug 27, 2015

ComboBox, Select, Slider, and Toggle have code that supposedly supports form reset. I.E. when the user presses a <form>'s reset button, those widgets inside the <form> revert to their original values.

However, AFAICT there are no automated tests for these features, and not even manual tests.

Furthermore, the API to specify the original value is unclear. For example, given markup like:

<form>
   <d-slider value=5>
       <input value=10>
  </d-slider>
</form>

Then it's unclear whether the slider's original value should be 5 or 10, and correspondingly whether the reset button should set the slider to 5 or 10. The code seems inconsistent, for example the slider's original value may be 5, but the reset button may set the value to 10.

Form auto-fill and back-button support are related. In both cases, on page load the browser sets a value for the <input> which the widget should obey. I'm not sure what form reset is supposed to do in that case, but the widgets should do whatever native controls do.

The original commits for the form reset handling were:

We should add automated tests, fix the code if it doesn't work, and document the right way to specify form widget's initial values.

@AdrianVasiliu
Copy link
Contributor

  • Select

With updated checkouts, I've tried the "reset" button in tests/functional/Select.html and it works for me as (I) expected. Tested with Chrome and FF / Win7. That is, after loading the test, I change the value of a single select, for instance I pick "Option 2". After "reset", it shows again "Option 1". Also, checking in the debugger the value prop. of the widget, it is consistent with what is shown in the DOM. It doesn't "clear" the value, it puts back the initial value. (The reset/submit buttons hold for the <select> inside the <form>, that is section #7 in the test.)

  • Combobox

Indeed, reset is broken. It was working some (long) time ago. In the debugger I see the _initValue() function does get called as expected, but for some reason nowadays this doesn't restore the initial value. Some change somewhere (in Combobox or outside) broke it. Here too, there's only manual testing. As you said, there should be an automatic test similar to the one existing for submit.

wkeese added a commit to ibm-js/delite that referenced this issue Aug 31, 2015
The default FormWidget and FormValueWidget afterFormResetCallback() methods
reset the widget according to the value (or checked property) of this.valueNode.
Strangely, there's no code in FormWidget and FormValueWidget to do that on initialization.
That should be added in the future.

Also, the original code in deliteful got the form reference from this.valueNode.form,
but that assumes that the widget is rendered before attachedCallback(),
which won't always be true (see #404).  So instead, I'm just tracing up the DOM tree
for the nearest <form> ancestor.

Fixes #423, refs ibm-js/deliteful#584.
wkeese added a commit that referenced this issue Aug 31, 2015
Refs ibm-js/delite#423, #584.

The form reset code for ComboBox, Select, Slider, and Toggle
was apparently added but never tested.  It's unclear if it worked before
or after this change.  The original commits for the form reset handling were:

* Combobox: 59e59c0
* Select: e80ca84
* Slider: c8cf2f0
* Toggle: 6ccd370
@wkeese
Copy link
Member Author

wkeese commented Sep 9, 2015

Combobox, Checkbox, and Radiobutton unconditionally create the this.valueNode <input> element in the template, rather than using the user-supplied one. If the user supplies one, you end up with two <input> controls inside the widget.

Select is a similar story except the template has a <select> node not an <input>

wkeese added a commit to ibm-js/delite that referenced this issue Sep 10, 2015
Also create embedded <input> (aka this.valueNode) if it does not exist.

The widget subclass should add this.valueNode to the DOM if it's not already there.
It shoudn't call appendChild() unnecessarily though as that will break back-button
support on IE.  See deliteful/tests/functional/StarRating-formback.html for test.
Also (if desired) the widget should set display:none on the <input>, either directly
or via a stylesheet.

Currently does not handle some complex cases, such as:

* deliteful/Select should support an embedded <select> rather than <input>
* deliteful/Checkbox and Radiobutton's embedded <input> also has "checked" property;
  should also sync that property.

Fixes #394, refs #423 tangentially, refs ibm-js/deliteful#584 too.
wkeese added a commit that referenced this issue Sep 10, 2015
@cjolif cjolif added this to the 0.8.0 milestone Oct 5, 2015
@clmath clmath modified the milestones: 0.9.0, 0.8.0 Nov 13, 2015
@wkeese wkeese removed this from the 0.9.0 milestone May 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants