Hi,
in Joomla 3 it was possible to get the name or current subform in data-base-name.
Example:
If there was a subform called "attributes" and its subsubform called "options", it was possible to get these names in event by attribute "data-base-name"
document.addEventListener('subform-row-add', ({ detail: { row } }) => {
<field name="attributes" type="subform"
<field name="options" type="subform"
Now all the items are anonymous:
Is there a way to get field names in the event to differentiate between each subforms?
Thank you, Jan
Labels |
Added:
No Code Attached Yet
|
Hi, thank you for the info:
Please try remove fieldname form foreach, and check if it work.
Yes, this did the trick. Now the question is, it is a bug or some specific feature?
The problematic part is, when there is no such information, you cannot get easily the subform which called the event. So if there are:
a) more levels of one form (form - subform - subform)
b) or more subform types in form
it is very problematic to detect which subform called the event. Finding this out from the html content of the form is very impractical and performance intensive.
BTW:
or try add fieldname attribute to your field XML.
This even does the trick.
Now the question is, it is a bug or some specific feature?
To me it is a bug.
I will make PR a bit later, if you do not make it faster :)
No problem for later PR, please link the PR here so I can test it.
Thank you very much.
Jan
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-09-27 15:35:33 |
Closed_By | ⇒ | Fedik |
Thank you, tested now: #35685 (comment)
This name should be equal to field name:
joomla-cms/libraries/src/Form/Field/SubformField.php
Line 249 in 9bd9e52
One difference I noticed between J3 and J4, it is
setup()
, tries to "read" the fieldname attribute, that looks strange to me:joomla-cms/libraries/src/Form/Field/SubformField.php
Lines 199 to 202 in 9bd9e52
If attribute fieldname does not exists, it reset the
fieldname
property of the field, and use__field
instead.Please try remove
fieldname
form foreach, and check if it work.or try add.fieldname
attribute to your field XMLBy default
fieldname
is equal to "raw" name of field (without group and without form control):joomla-cms/libraries/src/Form/FormField.php
Lines 540 to 543 in 81db97d