Omeka icon indicating copy to clipboard operation
Omeka copied to clipboard

Bad name for submit buttons in use

Open luku opened this issue 7 years ago • 1 comments

Hi, this issue took me really long time and pain to figure out. So hopefully it saves time for others. The problem is with forms where submit button has name="submit". If you need to halt the form submission (via preventDefault() or return false) and after executing some custom logic re-submit (continue submission of) the form again, it's impossible. The issue is this (in vanillaJS for better illustration):

var form = document.getElementById('item-form');
form.submit(); // throws Exception, method submit() is not defined
console.log(form.submit); // => <input type="submit" name="submit" ....>

As you can see form fields can be accessed by its names, and JavaScript cannot decide if we really want to replace/override submit() method with submit field, so it's definitely our responsibility. The problematic code is in form decorator and in many admin views (i.e. items/add, edit). I'm keen on replacing all the names in all views into "submit_add", "submit_edit" or "submit_save" to get rid of it. But at the same time, I'm not really sure how many people are relying on existence of the submit POST param in their own implementations. How do you think we should handle this issue?

luku avatar Mar 21 '17 19:03 luku

You can use some annoying nonsense to get at and call the submit method even when it's been shadowed by a form element:

Object.getPrototypeOf(form).submit.call(form);

There may well be a handful of places where people are looking for the "submit" name... I'll try to see if I can get anything concrete on that. Otherwise, yes it'd probably be a good idea to "fix" those names.

zerocrates avatar Mar 22 '17 17:03 zerocrates