Update JoomlaCalendar field with javascript Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 103
Joined: Wed Jan 20, 2016 10:58 pm

Update JoomlaCalendar field with javascript

Post by david0058 » Wed Sep 14, 2022 4:58 pm

J3.10.11

Hi,

Anyone ever manage to update a Joomla calendar field from Javascript ?

I have a component where the edit view uses ajax to pull details for an event selected from a list box, and while I have no problem updating all the text fields etc. with the data returned, I can't for the life of me see how to update my start and end date fields which are rendered as calendars. Updating the input box of each control is fine, but I can't figure out how to update the corresponding calendar widgets.

Any help appreciated !

David
Last edited by toivo on Wed Sep 14, 2022 9:30 pm, edited 1 time in total.
Reason: mod note: retitled as requested by OP

david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 103
Joined: Wed Jan 20, 2016 10:58 pm

Re: Update Joomla

Post by david0058 » Wed Sep 14, 2022 9:04 pm

Sorry mods, I seem to have lost half the subject, meant to be "Update JoomlaCalendar field with javascript"

david0058
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 103
Joined: Wed Jan 20, 2016 10:58 pm

Re: Update JoomlaCalendar field with javascript

Post by david0058 » Thu Sep 15, 2022 9:54 am

My god that was painful ... and hacky (accessing 'private' instance data etc.)

For anyone interested:

Code: Select all

// update first calendar field on the page with e.g. "2022-10-15T15:00:00.000Z"

start_elem = jQuery('#jform_start_datetime');
if (start_elem){
	let newDate = new Date(rcvd_data.start.local);
	let dateValue = newDate.toISOString().replace('T', ' ').replace('.000Z', '');

	start_elem.val(dateValue);
	start_elem.attr('data-alt-value',dateValue);

	field_cal = jQuery('.field-calendar')[0]._joomlaCalendar;
	if (field_cal)
		field_cal.setDate(newDate);
}
I'd have preferred to have been able to find the JoomlaCalendars using the input field class/id rather than having to know the order on the page (zero-th = start date, first = end date etc.) but at least this is working.


Locked

Return to “Joomla! 3.x Coding”