-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
[form] Fix nested form support natively #2792
Comments
Here is example of not working submit - https://jsfiddle.net/ebnvam9r/ Here are all atk4/ui usages (old changes in the commit) that require explicit form tag currently - atk4/ui@b239458. And failing example with nested form with duplicate names: https://jsfiddle.net/kauq125z/ |
api behaviour module
-$form = $module.closest(selector.form)
+$form = $module.find('> form').addBack().closest(selector.form) Would fix it, but api behaviour module works on form/inputs per html spec, ie. not on form behaviour moduleThis module does work primary on Currently the module does not resolve native form tag in any way. If I understand the current impl. correctly - https://github.com/fomantic/Fomantic-UI/blob/afea456335/src/definitions/behaviors/form.js#L160, the submit event is currently working together with the native form events by coincidence when the module element is also a form tag. ⏩⏩ In order to work with nested forms, it must ignore any fields of inner form, ie, any DOM subtrees starting with And if integration of submit/reset with the native form is desired, the module must: Resolve the native form tag, at least by the most strict selector: And listen on native form tag events, per https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement#events there are 3 native events - |
The events can be fixed by:
The JS for nested forms can be fixed by: in https://github.com/fomantic/Fomantic-UI/blob/afea456335/src/definitions/behaviors/form.js#L119 -$field = $module.find(selector.field);
+$field = $module.find(selector.field).filter((i, elem) => $(elem).parentsUntil($module, '.ui.form').length === 0); of course this needs to be fixed for every method that search the form/$module subtree. CSS must be fixed to reset some classes once inner demo: https://jsfiddle.net/kauq125z/1/ (with form.js copied with the diff above applied) |
Feature Request
(originally posted in #2791, that issue was based on mixed (on owning div / form tag directly)
.form()
usage, this issue is feature request to fix the support natively and allow.form()
to be used on the owning div with (self closed/empty) form tag inside)Nested forms theory and current Fomantic-UI impl.
please see atk4/ui#1275
In atk4/ui all html forms code look like
<div id="fff"><form id="fff_form"></form><input form="fff_form">
to overcome the form tag limitation and allow form nesting. This is the only possible solution per html forms spec.In atk4/ui I tried to fix all JS
.form()
calls to be done onform
tag ($('fff_form').form(
instead of$('fff').form(
) but this is not working with Fomantic-UI as well, as:a)
success
class is not added to the owning form div (with idfff
) causing all success messages to be hiddenb)
$('fff_form').form('add prompt', ...)
errors withForm: Field identifier email1 not found
So calling
.form()
on a form tag is not a solution either.Looking into https://github.com/fomantic/Fomantic-UI/blob/develop/src/definitions/behaviors/form.js code Fomantic-UI simply expects all form components to be a contained in the module element.
Current atk4/ui impl./usage
In atk4/ui#1275 I found some sweet spot to do some
.form()
calls on the owning div and some on the form tag directly:This is obviously a hack. As Fomantic-UI module expects the module to be a parent of all form subviews, I propose to fix the nested forms (via official/W3 immediately self closing form tag) support by:
a) allow to specify the form element selector explicitly
b) if the selector is not specified, locate&use the first form tag relative/within the module
c) if the explicitly passed element is not a form tag or no form tag was found, emit an error
The text was updated successfully, but these errors were encountered: