-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
We had a scenario with a form with multiple submit buttons with different formaction attributes. Currently the library does not support that.
Suggest changing post-validation to support multiple submit buttons with name/values, and using event.submitter to determine what the correct action should be:
import { hasNameValue, hasFormactionValue } from './utils';
import {
createButtonValueNode,
cleanupButtonValueNode
} from '../dom';
import { PREHOOK_DELAY } from '../constants';
export const postValidation = (event, resolve, store) => {
const { settings, form } = store.getState();
let buttonValueNodes = [];
let cachedAction = false;
const submit = () => {
if (settings.submit) settings.submit();
else form.submit();
buttonValueNodes.length && buttonValueNodes.forEach(node => cleanupButtonValueNode(node));
cachedAction && form.setAttribute('action', cachedAction);
};
const formSubmitButtons = Array.from(form.querySelectorAll('[type="submit"]'));
formSubmitButtons.forEach(formSubmitButton => {
if (hasNameValue(formSubmitButton)) {
buttonValueNodes = [...buttonValueNodes,createButtonValueNode(formSubmitButton, form)];
}
});
if (event.submitter && hasFormactionValue(event.submitter)){
cachedAction = form.getAttribute('action');
form.setAttribute('action', event.submitter.getAttribute('formaction'));
}
if (event && event.target) {
if (settings.preSubmitHook) {
settings.preSubmitHook();
window.setTimeout(submit, PREHOOK_DELAY);
} else submit();
}
return resolve(true);
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels