Skip to content
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

Subform-repeatable javascript #39964

Closed
brianteeman opened this issue Feb 28, 2023 · 18 comments
Closed

Subform-repeatable javascript #39964

brianteeman opened this issue Feb 28, 2023 · 18 comments

Comments

@brianteeman
Copy link
Contributor

Steps to reproduce the issue

Create a repeatable subform that contains a field that uses js

You can add this code to mod_article_categories.xml as a test

<field
	name="field-name"
	type="subform"
	label="Subform Field"
	multiple="true"
	min="1"
	max="10"
	>
	<form>
		<fieldset name="basic" addfieldprefix="Joomla\Component\Categories\Administrator\Field">
			<field
				name="parent"
				type="modal_category"
				label="MOD_ARTICLES_CATEGORIES_FIELD_PARENT_LABEL"
				extension="com_content"
				filter="integer"
				published=""
				select="true"
				new="true"
				edit="true"
				clear="true"
			/>
		</fieldset>
	</form>
</field>

Expected result

A working repeatable field to select the category

Actual result

Only the first occurence works. All subsequent fields do not as the modal is empty

Additional comments

I understand that this is because the modal_category field uses javascript to populate the iframe in the body of the modal but as it does this on page load it does not work for the repeated field because it is not present on page load.

I assume that there could be some javascript that could be instantiated when a subform row is added that would populate the field as required. But I don't have a clue with js to know where to start

cc @Fedik @dgrammatiko

@dgrammatiko
Copy link
Contributor

Some time ago I spend some time resurrecting the pr for the modal fields #39351 and asked if this was b/c or not. Didn’t get any answer so I closed it

@brianteeman
Copy link
Contributor Author

not suprised that you got no feedback on #39351 as it contained no information about what changed and why.

Looking at it now I still don't know if its just a refactoring or if it indeed resolves the issue I have.

Surely (to my non js dev mind) its just a case of having some js to watch if a new row is added and then do what is necessary to configure the field

@dgrammatiko
Copy link
Contributor

@brianteeman you're wrong: #38404 (comment)

@brianteeman
Copy link
Contributor Author

and how is anyone supposed to know that? You ddidn't link to 38404 anywhere in 39351

@brianteeman
Copy link
Contributor Author

and anyway 38404 is completely unrelated to the issue I am reporting

@dgrammatiko
Copy link
Contributor

Surely (to my non js dev mind) its just a case of having some js to watch if a new row is added and then do what is necessary to configure the field

Not really, the fields with a modal need to be client side rendered and not prerendered from the php side. Me an Fedik investigated on the possible solutions:

and how is anyone supposed to know that? You ddidn't link to 38404 anywhere in 39351

I wasn't expecting anyone to participate on that PR, only the people I mentioned in the issue

and anyway 38404 is completely unrelated to the issue I am reporting

It's the same issue and it's occurring almost in every field that has a modal...

@brianteeman
Copy link
Contributor Author

and anyway 38404 is completely unrelated to the issue I am reporting

It's the same issue and it's occurring almost in every field that has a modal...

it is not the same issue. Please re-read what I wrote and not what you think I wrote.

and the site I am testing on does NOT have mod_security enabled!

@Fedik
Copy link
Member

Fedik commented Feb 28, 2023

As Dimitris wrote, almost any modal field will not work in subform.

And other fields that have extra javascript logic, should be coded to work in subform as web component or with this event: https://docs.joomla.org/J4.x:ClientSideEvents#joomla:updated

@brianteeman
Copy link
Contributor Author

and thats what I am asking for

@Fedik
Copy link
Member

Fedik commented Feb 28, 2023

Sadly the docs page for ClientSideEvents almost impossible to find in Google.

@brianteeman
Copy link
Contributor Author

I still don't know what to do with that information

I assume that there could be some javascript that could be instantiated when a subform row is added that would populate the field as required. But I don't have a clue with js to know where to start

@Fedik
Copy link
Member

Fedik commented Feb 28, 2023

There also some examples in https://docs.joomla.org/Subform_form_field_type
They are old for jquery and need to be updated, but the idea the same.
You basicaly need to run javascript to iniitialise when page is loaded (on DOMContentLoaded) and when new row added (on joomla:updated event.)

Like here example

// On document loaded
document.addEventListener('DOMContentLoaded', updateSelectboxColour, true);
// On Joomla updated
document.addEventListener('joomla:updated', updateSelectboxColour, true);

@dgrammatiko
Copy link
Contributor

I still don't know what to do with that information

Check the comments from me and @Fedik on another field: #35678 (review)

@brianteeman
Copy link
Contributor Author

Thanks @Fedik I will see if I can understand that.

What I don't understand why you both keep saying things like this instead of it actually being fixed. So please do not close this. Maybe someone else will have their itch scratched

@dgrammatiko
Copy link
Contributor

What I don't understand why you both keep saying things like this instead of it actually being fixed

It's not that easy and involves some sort of B/C break. For example the selecting of a category has a dynamic function (created on PHP at run time) passed in the URL:

$urlSelect = $linkCategories . '&amp;function=jSelectCategory_' . $this->id;

This is wrong on every conceivable way but fixing it involves some level of B/C break. These were the kind of solutions we were looking at, both on the discussion and the RFC. Also, whenever a b/c break is required, people get extremely impolite on their responses, so that's also not very motivating to work on such issues.

@Fedik
Copy link
Member

Fedik commented Feb 28, 2023

To fix all that in proper way, need to rewrite a looooooot of our js with some b/c break, and I not really in mood of doing it 😄

@brianteeman
Copy link
Contributor Author

FWIW I just tested #39344 and while (as you state) it is not production ready it does successfully resolve the issue I am reporting here

@Fedik
Copy link
Member

Fedik commented Nov 11, 2023

This is fixed with:

Also see other linked PR in #32663 (comment)

If some specific field is broken, then better open a new issue for that field.

@Fedik Fedik closed this as completed Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants