When the default calendar widget is used to choose a date, the "change" event for the attached input field is not fired.
Create a field of type="calendar" in an admin form. Then run the following script to attach the function to catch the "change" event.
var calendar = jQuery(...);
calendar.change(function() {
console.log("hi");
});
When typing in the box or selecting the date from the calendar widget with the mouse, the string "hi" should be logged to the console.
The string "hi" is only logged to the console when typing in the box, not when a date on the calendar widget is clicked.
Joomla 3.4!
This is really irritating if you want to write some custom validation for two dates that depend on each other (e.g. start date and end date).
Category | JavaScript | ⇒ | Fields JavaScript |
@flash1452 Thanks for your reply. Unfortunately (correct me if I'm wrong) I don't think the Joomla calendar widget uses the JQuery datepicker. Certainly jQuery("#form_startdate").datepicker
is undefined.
Even if it does, shouldn't the Joomla calendar widget implement the standard event API?
@MatthewDaggitt If the standard event API is not working in this case then I think we can go for this little hack if it is possible.
Hi,
I am trying to reproduce the issue but I don't have a clear idea on how to perform "Create a field of type="calendar" in an admin form".
Could you please provide a detailed set of steps?
So in admin/models/forms/event.xml I have:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
...
<field
name="startdate"
type="calendar"
label="Start date"
default="2016-01-01"
description="The date the event starts on? (in the form YYYY-MM-DD)"
format="%Y-%m-%d"
class="validate-startdate"
/>
...
</fieldset>
</form>
and in admin/views/event/tmpl/edit.php I have:
...
<script type="text/javascript">
var calendar = jQuery('.validate-startdate');
calendar.change(function() {
console.log("hi");
});
</script>
Is there anything else you need? If needs be I can link the full code of the entire component...
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-12-09 13:06:29 |
Closed_By | ⇒ | brianteeman |
As the entire code for the calendar has been changed for 3.7 I am closing this. If you still have issues with the calendar code in 3.7 please open a new issue
@MatthewDaggitt I think a better way to trigger this event will be to use datepicker of Jquery
http://stackoverflow.com/questions/11610797/trigger-function-when-date-is-selected-with-jquery-ui-datepicker