Talk

Calendar form field type

From Joomla! Documentation

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

If you need MM-DD-YYYY format create a new calendar type. In 2.5.8 setting format to %m-%d-%Y still throws fatal error.

See long discussion here : http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=20826

For my requirement the solution was to create a new type using jQuery UI datepicker. Lots of formatting options

<?php defined('_JEXEC') or die('Restricted access'); /**

* Resource Manager Extension
* 
* @author Micah Fletcher
* @copyright 2012 Extensible Point Solutions Inc. All Right Reserved
* @license GNU GPL version 3, http://www.gnu.org/copyleft/gpl.html
* @link http://www.exps.ca
* @version 1.0.0
* @since 2.5.6
* */

jimport('joomla.form.formfield'); /**

* Field JQuery UI DatePicker form field class
*/

class JFormFieldJuiDatePicker extends JFormField {

 /**
  * field type
  * @var string
  */
 protected $type = 'JuiDatePicker';
 /**
  * Method to get the field input markup
  */
 protected function getInput() {
   //script in parent
   $js = 'jQuery(function() {
   jQuery("#'.$this->id.'").datepicker({ 
     showButtonPanel: true,
     showOn: "both",
     dateFormat: "'.$this->element['format'].'",
     defaultDate: "'.$this->element['defaultDate'].'",
     changeYear: true     
      });

});';

   JFactory::getDocument()->addScriptDeclaration($js);
   // The input field
   // class='required' for client side validation
   $class = ;
   if ($this->required) {
       $class = ' class="required"';
   }
   $html = array();
   $html[] = '<input ' . $class . ' type="text" name="' . $this->name . '" id="' . $this->id . '" size="30" value="' . $this->value . '" />';
   return implode("\n", $html);
 }

}