public function Field($properties = array()) { $config = array('separator' => $this->getConfig('separator') ? $this->getConfig('separator') : ', ', 'showcalendar' => $this->getConfig('showcalendar'), 'isoDateformat' => $this->getConfig('dateformat'), 'jquerydateformat' => DateField_View_JQuery::convert_iso_to_jquery_format($this->getConfig('dateformat')), 'min' => $this->getConfig('min'), 'max' => $this->getConfig('max')); // Add other jQuery UI specific, namespaced options (only serializable, no callbacks etc.) // TODO Move to DateField_View_jQuery once we have a properly extensible HTML5 attribute system for FormField $jqueryUIConfig = array(); foreach ($this->getConfig() as $k => $v) { if (preg_match('/^jQueryUI\\.(.*)/', $k, $matches)) { $jqueryUIConfig[$matches[1]] = $v; } } if ($jqueryUIConfig) { $config['jqueryuiconfig'] = Convert::array2json(array_filter($jqueryUIConfig)); } $config = array_filter($config); foreach ($config as $k => $v) { $this->setAttribute('data-' . $k, $v); } // Three separate fields for day, month and year (not available for multidates) if ($this->getConfig('dmyfields')) { user_error("MultiDateField doen't work with separate fields for day/month/year"); } // Default text input field $html = parent::Field(); return $html; }
function testConvert() { $this->assertEquals( 'M d, yy', DateField_View_JQuery::convert_iso_to_jquery_format('MMM d, yyyy') ); $this->assertEquals( 'd/mm/yy', DateField_View_JQuery::convert_iso_to_jquery_format('d/MM/yyyy') ); $this->assertEquals( 'dd.m.yy', DateField_View_JQuery::convert_iso_to_jquery_format('dd.M.yyyy'), 'Month, no leading zero' ); $this->assertEquals( 'dd.mm.yy', DateField_View_JQuery::convert_iso_to_jquery_format('dd.MM.yyyy'), 'Month, two digit' ); $this->assertEquals( 'dd.M.yy', DateField_View_JQuery::convert_iso_to_jquery_format('dd.MMM.yyyy'), 'Abbreviated month name' ); $this->assertEquals( 'dd.MM.yy', DateField_View_JQuery::convert_iso_to_jquery_format('dd.MMMM.yyyy'), 'Full month name' ); }
/** * Return the form field. * * @todo Make a jQuery safe form field. The current CalendarDropDown * breaks on the front end. */ public function getFormField() { // scripts for jquery date picker Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery.ui.core.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery.ui.datepicker.js'); $dateFormat = DateField_View_JQuery::convert_iso_to_jquery_format(i18n::get_date_format()); Requirements::customScript(<<<JS \t\t\t(function(jQuery) { \t\t\t\t\$(document).ready(function() { \t\t\t\t\t\$('input[name^=EditableDateField]').attr('autocomplete', 'off').datepicker({ dateFormat: '{$dateFormat}' }); \t\t\t\t}); \t\t\t})(jQuery); JS , 'UserFormsDate'); // css for jquery date picker Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui-1.8rc3.custom.css'); $default = $this->getSetting('DefaultToToday') ? date('d/m/Y') : $this->Default; return new DateField($this->Name, $this->Title, $default); }
function Field($properties = array()) { $config = array('showcalendar' => $this->getConfig('showcalendar'), 'isoDateformat' => $this->getConfig('dateformat'), 'jqueryDateformat' => DateField_View_JQuery::convert_iso_to_jquery_format($this->getConfig('dateformat')), 'min' => $this->getConfig('min'), 'max' => $this->getConfig('max')); // Add other jQuery UI specific, namespaced options (only serializable, no callbacks etc.) // TODO Move to DateField_View_jQuery once we have a properly extensible HTML5 attribute system for FormField $jqueryUIConfig = array(); foreach ($this->getConfig() as $k => $v) { if (preg_match('/^jQueryUI\\.(.*)/', $k, $matches)) { $jqueryUIConfig[$matches[1]] = $v; } } if ($jqueryUIConfig) { $config['jqueryuiconfig'] = Convert::array2json(array_filter($jqueryUIConfig)); } $config = array_filter($config); foreach ($config as $k => $v) { $this->setAttribute('data-' . $k, $v); } // Three separate fields for day, month and year if ($this->getConfig('dmyfields')) { // values $valArr = $this->valueObj ? $this->valueObj->toArray() : null; // fields $fieldNames = Zend_Locale::getTranslationList('Field', $this->locale); $fieldDay = NumericField::create($this->name . '[day]', false, $valArr ? $valArr['day'] : null)->addExtraClass('day')->setAttribute('placeholder', $this->getConfig('dmyplaceholders') ? $fieldNames['day'] : null)->setMaxLength(2); $fieldMonth = NumericField::create($this->name . '[month]', false, $valArr ? $valArr['month'] : null)->addExtraClass('month')->setAttribute('placeholder', $this->getConfig('dmyplaceholders') ? $fieldNames['month'] : null)->setMaxLength(2); $fieldYear = NumericField::create($this->name . '[year]', false, $valArr ? $valArr['year'] : null)->addExtraClass('year')->setAttribute('placeholder', $this->getConfig('dmyplaceholders') ? $fieldNames['year'] : null)->setMaxLength(4); // order fields depending on format $sep = $this->getConfig('dmyseparator'); $format = $this->getConfig('dateformat'); $fields = array(); $fields[stripos($format, 'd')] = $fieldDay->Field(); $fields[stripos($format, 'm')] = $fieldMonth->Field(); $fields[stripos($format, 'y')] = $fieldYear->Field(); ksort($fields); $html = implode($sep, $fields); // dmyfields doesn't work with showcalendar $this->setConfig('showcalendar', false); } else { $html = parent::Field(); } return $html; }
function testConvert() { $this->assertEquals('M d, yy', DateField_View_JQuery::convert_iso_to_jquery_format('MMM d, yyyy')); $this->assertEquals('d/mm/yy', DateField_View_JQuery::convert_iso_to_jquery_format('d/MM/yyyy')); $this->assertEquals('dd.mm.yy', DateField_View_JQuery::convert_iso_to_jquery_format('dd.MM.yyyy')); }