Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 4745500

Browse files
Stop pretending we can serialize buttons in a form
The library previously serialized all buttons present in a form, saving name and value attributes as key/value pairs. Standard HTML forms do not do this, but save name and value only for the button that was used to submit the form. This change stops serialization for any button data, to avoid the incorrect assumption that the data stem from the submitted button (it doesn't, buttons are serialized sequentially). At some later point, the code might be extended to capture the data for the submitted button, but that would not be an easy change, and popular serialization libraries don't implement this feature for the stated reason.
1 parent 71cb89d commit 4745500

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

docs/reference/html.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ By combining the above code with an :js:class:`html.Form`, it can become part of
149149

150150
The above screen, inserted into an experiment, will display the form, and wait for the user to submit it using the supplied button. When this occurs, the form contents will automatically be transferred into the experiment's data set, and whichever value was entered into the specified field will be saved into the variable ``participant-id``.
151151

152+
.. caution::
153+
The :js:class:`html.Form` differs from standard ``HTML`` forms (those that are sent to a server, which responds with a new page) in one important point: It does *not* save information about the ``<button>`` used to submit the ``<form>`` data. This is because the information is not made available within the page itself.
154+
155+
If you are looking to capture a response to one of several buttons, we recommend using an :js:class:`html.Screen` instead, and defining a distinct :js:attr:`response <options.responses>` for clicks on every button.
156+
152157
.. js:class:: html.Form([options])
153158

154159
An :js:class:`html.Form` accepts the same options and provides the same methods the :js:class:`html.Screen` does, with a few additions:

packages/library/src/html.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,6 @@ export class Form extends Screen {
139139
// no default
140140
}
141141
break
142-
case 'button':
143-
switch (element.type) {
144-
case 'button':
145-
case 'submit':
146-
case 'reset':
147-
output[element.name] = element.value
148-
break
149-
default:
150-
}
151-
break
152142
default:
153143
} // outer switch
154144
}) // iterate across elements

packages/library/test/html.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,6 @@ describe('HTML-based components', () => {
223223
})
224224
})
225225

226-
it('serializes buttons', () => {
227-
f.options.el.innerHTML = '' +
228-
'<form>' +
229-
' <button name="button" value="value">' +
230-
'</form>'
231-
232-
assert.deepEqual(f.serialize(), {
233-
'button': 'value'
234-
})
235-
})
236-
237226
const exampleForm = '' +
238227
'<form>' +
239228
' <input type="text" name="text_input" value="text_input_contents">' +
@@ -281,7 +270,6 @@ describe('HTML-based components', () => {
281270
return f.run().then(() => {
282271
f.submit()
283272
assert.equal(f.data.text_input, 'text_input_contents')
284-
assert.equal(f.data.button, 'value')
285273
})
286274
})
287275

0 commit comments

Comments
 (0)