jQuery('#jform_publish_down').on('change', function() { alert('test'); });
The event will be triggered (=> alert test)
No trigger
I'm not sure, why there is a vanilla JS calendar without any jQuery hooks in a system which relays on jQuery...
To check the event use:
jQuery('#jform_publish_down').trigger('change');
Delegation should probably work, too
Labels |
Added:
?
|
Hi @dgt41 ,
Thank you for your answer!
Could you also say something about event delegation?
(The reason for jQuery events is, that with vanilla JS, I have to implement a mapping for the events...)
@bembelimen actually looking at the code I didn't see any code for triggering the change event, or I was too hurry. I guess if the event is triggered (vanilla or jQuery) will eventually bubble up to jQuery. Give me few days and I will come back with some more solid answers here
Category | ⇒ | JavaScript |
Status | New | ⇒ | Discussion |
@dgt41 any updates here?
You can add the onchange
event listener to the calendar form field, like so:
<field
type="calendar"
onchange="Joomla.inputHasChanged();"
/>
Then in your JS:
var Joomla = Joomla || {};
(function(Joomla) {
Joomla.inputHasChanged = function() {
alert('changed!');
// You can do some more jazzy stuff here.
}
document.addEventListener('DOMContentLoaded', function() {
Joomla.inputHasChanged();
});
})(Joomla);
Yeah, but I don't understand why there is no default implementation....
@bembelimen The calendar was a huge change, must have been missed out.
@bembelimen @C-Lodder well it didn't exist in the old calendar and nobody ask for it during the testing period, but it's fairly simple to add a listener for an event, or dispatch an Event from the calendar.
@dgt41 do you have any plans to implement it? That would be great!
Labels |
Added:
J3 Issue
|
Status | Discussion | ⇒ | Confirmed |
Is still still open? Any hint how to fix it?
@coolcat-creations supporting jQuery events in 2020 is not very bright idea. It wasn't back in 2017...
Events are events. Doesn't matter if they're called in jQuery or vanilla JS.
I'll start looking into this now.
The problem being is that the value is being set via Javascript, so the normal event listener don't apply. You can add a custom event:
Add the following to Joomla's core calendar:
const event = new Event('change');
this.inputField.dispatchEvent(event);
Then in your own code:
element.addEventListener('change', () => {
console.log('has changed')
}, false)
jQuery('#element').on('change', () => {
console.log('Look Mum....I can use jQuery too!')
})
Comment #17515 (comment)
by @dunkmark
is SPAM. Please delete.
Status | Confirmed | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-03-20 09:54:20 |
Closed_By | ⇒ | alikon |
@bembelimen why not:
??
This works in IE8 and all other browsers, so honestly I don't see a reason to mix jQuery when native javascript fulfils all our needs.
Any particular reason why we need to care for jQuery's own events?