DirtySubmit should use FormData

https://docs.gitlab.com/ee/development/new_fe_guide/modules/dirty_submit.html

Whilst testing a fix for a bug in DirtySubmit (https://gitlab.com/gitlab-org/gitlab-ce/issues/53856), I found our pattern to be suboptimal and annooooooooying. I take full responsibility for this.

We currently check for changes in a form by accessing input element attributes directly, this means we have special conditions for checkboxes and radios where we check for the checked attribute instead of the value attribute of the element.

#input{ id: 'radio1', type: 'radio', name: 'radios', value: 'foo', checked: true }
#input{ id: 'radio2', type: 'radio', name: 'radios', value: 'bar' }

For the markup above, we are checking when the checked attribute changes on #radio1 and when the checked attribute changes on #radio2.

If we used FormData, we could use formData.get('radios') to return the value of whichever radio is checked. It will return null for unchecked checkboxes and normal value attribute behaviour for text fields.

If we can implement it this way, we can decouple DirtySubmit from the specifics of the form element, and focus only on the data of the form.

There is still a little to put together, so I'll try to resist refactoring DirtySubmit and focus on getting this fix in with its specs. But I'm just dropping this here for transparency.

/cc @dennis

Assignee Loading
Time tracking Loading