Deprecation of JHtml::_('behavior.calendar') and a problem with the new date picker

81 views
Skip to first unread message

chris....@gmail.com

unread,
May 3, 2017, 5:05:31 AM5/3/17
to Joomla! CMS Development
First of all, I do like the new date picker. It's much nicer than the old one. Well done!

But unfortunately, I have used JHtml::_('behavior.calendar') a lot. In most cases I can replace it with some code to dynamically create and render a form field:

$initial_date_value = "2017-12-31";
$form = JForm::getInstance('a_form', '<form> </form>');
$element = new SimpleXMLElement('<fieldset name="a_fieldset"><field name="a_field" type="calendar" showtime="false" /></fieldset>');
$form->setField($element);
$form->setValue("a_field", null, $initial_date_value);
echo $form->getInput("a_field");

That's not exactly what I'm doing, but the above sample works, and I can add all the relevant options to the field definition dynamically, which is what I need.

The problem arises when I have two related date fields, say a start date and an end date. With the old MooTools date picker, I have some Javascript that hooks the onSelect event provided by the calendar code. When a user picks a date for the first field, the first date becomes the default date for the second field.

I eventually found that the new calendar has an equivalent event called onUpdate, which duly fires when a date is selected. It's not easy to hook it but it can be done by finding the relevant JoomlaCalendar object in a domready function. I will post the code if anyone wants it.

However, copying the first date into the second text field does not work as expected. It looks ok, but the inserted date does not become the default date for the date picker. The picker still starts at the date that was set when it was created. This is also a problem when entering a date using the keyboard. The date you enter does not become the default date for the date picker.

So my questions are:

1) Is there an easier way to create date fields?
2) Is there an easier way to hook the onUpdate event?
3) Is there any documentation for the new date picker?
4) Is the keyboard entry issue acceptable, or is it a bug?
5) Is there any way to set a new default date for an existing JoomlaCalendar object?

Sorry to ask so many questions but any help at all would be hugely appreciated.
Reply all
Reply to author
Forward
0 new messages