No Code Attached Yet
avatar PhocaCz
PhocaCz
27 Sep 2021

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"

img

Now all the items are anonymous:

img

Is there a way to get field names in the event to differentiate between each subforms?

Thank you, Jan

avatar PhocaCz PhocaCz - open - 27 Sep 2021
avatar joomla-cms-bot joomla-cms-bot - change - 27 Sep 2021
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Sep 2021
avatar Fedik
Fedik - comment - 27 Sep 2021

This name should be equal to field name:

$data['fieldname'] = $this->fieldname;

One difference I noticed between J3 and J4, it is setup(), tries to "read" the fieldname attribute, that looks strange to me:

foreach (array('fieldname', 'formsource', 'min', 'max', 'layout', 'groupByFieldset', 'buttons') as $attributeName)
{
$this->__set($attributeName, $element[$attributeName]);
}

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 XML.

By default fieldname is equal to "raw" name of field (without group and without form control):

case 'name':
$this->fieldname = $this->getFieldName((string) $value);
$this->name = $this->getName($this->fieldname);
break;

avatar Fedik
Fedik - comment - 27 Sep 2021

It was added here #24711, but I do not see a reason why.

avatar PhocaCz
PhocaCz - comment - 27 Sep 2021

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?

img

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.

avatar PhocaCz
PhocaCz - comment - 27 Sep 2021

BTW:

or try add fieldname attribute to your field XML.

This even does the trick.

avatar Fedik
Fedik - comment - 27 Sep 2021

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 :)

avatar PhocaCz
PhocaCz - comment - 27 Sep 2021

No problem for later PR, please link the PR here so I can test it.

Thank you very much.

Jan

avatar Fedik Fedik - change - 27 Sep 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-09-27 15:35:33
Closed_By Fedik
avatar Fedik Fedik - close - 27 Sep 2021
avatar Fedik
Fedik - comment - 27 Sep 2021

Please test #35685

avatar PhocaCz
PhocaCz - comment - 27 Sep 2021

Thank you, tested now: #35685 (comment)

Add a Comment

Login with GitHub to post a comment