User tests: Successful: Unsuccessful:
Pull Request for Issue # .
The 'showon' feature for forms doesn't currently provide a setup method when adding a new form to the DOM on the fly, rather than on domready. There's a way to add a repeated instance to an existing form, which uses some additional data attributes to add repeat numbering, but my use case involves adding new forms in the backend through AJAX.
This change just renames setUpShowon as Joomla.setUpShowon, so it can be called through the global Joomla object..
Pick any backup param that has showon, like global settings "send mail". Apply this change. The showon feature still works. :)
None
Status | New | ⇒ | Pending |
Category | ⇒ | JavaScript |
OK, so how do we achieve that?
-- hugh
for Joomla! 3:
you can make a pull request to rename setUpShowon
to Joomla.setUpShowon
,
so you can use it in your script:
function ajaxCallback() {
// do your stuf ...
var blablaContainer = ...;
// call setUpShowon
Joomla.setUpShowon(blablaContainer);
}
for Joomla! 4 there will be a custom events, see #16016 ,
so you will be able to do in your script:
function ajaxCallback() {
// do your stuf ...
var blablaContainer = ...;
// dispatch custom event to inform about DOM updates
Joomla.Event.dispatch(blablaContainer, 'joomla:updated');
}
Status | Pending | ⇒ | Information Required |
@cheesegrits yes, looks good now
@Fedik - cool.
BTW, where's a good place to bounce some stuff off you about the event dispatcher in 4.0, as it relates to bootstrap? I've run across an immediate use for it, related to the same issue I'm addressing here, of adding entire forms to the DOM. Similar problem, that the bootstrap-init.js only runs on domready. I've patched it locally in 4.0 to add your joomla:updated event handling, but that raised a problem with Joomla.loadOptions() ...
I guess I can go ahead an do a PR for those changes, and maybe get your input there?
@cheesegrits you can check #16016 as starting point, there introduced Joomla.Event.dispatch
in core.js
and #18864 as an example how it can work
I guess I can go ahead an do a PR for those changes, and maybe get your input there?
I do not know about a plans for bootstrap-init.js
in Joomla! 4, but yes, any help are welcome
I have tested this item
on review,
this just rename setUpShowon
to Joomla.setUpShowon
without logic changes,
and this changes allow to extension developers to easily use showon
feature with their AJAX code, or other dynamic code
@cheesegrits but if you need it only for Joomla! 4, then there it is fixed b10572d (in another way)
@cheesegrits any Statement on Comment above by @Fedik?
@franz-wohlkoenig oops, sorry, misread his comment and didn't think it needed a response. I need this functionality in 3.x and 4.x. So yes, still need this merged.
Status | Information Required | ⇒ | Discussion |
Do you have to apply the same changes to cms.js
?
Presumably cms.js is the compressed version.
I have tested this item
Status | Discussion | ⇒ | Ready to Commit |
Status "Ready To Commit".
are we sure that setUpShowon only lives in the closure and is private till this PR?
@HLeithner I did not seen it anywhere else in the core
hm yes, probably
But the idea is to call it once per new container
, example when part of the page was updated dynamically,
that the case with "subform row".
Currently this was "isolated".
After this patch Joomla.setUpShowon()
can be called by extension developers, who want update the form dynamically (via ajax example), and be able to use ShowOn feature.
Programmers are lazy, they will simply use the form as container... is there a simple way to prevent the double attach?
I can think about 2 way:
Can be as a data attribute data-showon-attached="true"
or something similar
Would be good, jQuery('input').data('shown-attached', true);
should be easy to implement.
Can you do this?
me? yea, I guess :)
I just thought, is it worth to do it for j3.
Because for j4 Joomla.setUpShowon no need, there already used joomla.updated
event.
Status | Ready to Commit | ⇒ | Pending |
set label ´Updates Requested´ again.
Closing in favour of #32061 . Thanks @cheesegrits for this PR here as a base for the fix.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-01-16 13:46:42 |
Closed_By | ⇒ | richard67 | |
Labels |
Added:
?
|
your fix is incorrect,
subform
script do not havesubform-container-add
event,to fix what you asked you should call
setUpShowon
from your ajax script, but first setUpShowon need to be underJoomla.setUpShowon
scope