1<?php 2/** 3 * Class helper_plugin_bureaucracy_fielddate 4 * 5 * A date in the format YYYY-MM-DD, provides a date picker 6 */ 7class helper_plugin_bureaucracy_fielddate extends helper_plugin_bureaucracy_fieldtextbox { 8 /** 9 * Arguments: 10 * - cmd 11 * - label 12 * - ^ (optional) 13 * 14 * @param array $args The tokenized definition, only split at spaces 15 */ 16 public function initialize($args) { 17 parent::initialize($args); 18 $attr = array( 19 'class' => 'datepicker edit', 20 'maxlength'=>'10' 21 ); 22 if(!isset($this->opt['optional'])) { 23 $attr['required'] = 'required'; 24 $attr['class'] .= ' required'; 25 } 26 $this->tpl = form_makeTextField('@@NAME@@', '@@VALUE@@', '@@DISPLAY@@', '@@ID@@', '@@CLASS@@', $attr); 27 } 28 29 /** 30 * Validate field input 31 * 32 * @throws Exception when empty or wrong date format 33 */ 34 protected function _validate() { 35 parent::_validate(); 36 37 $value = $this->getParam('value'); 38 if (!is_null($value) && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { 39 throw new Exception(sprintf($this->getLang('e_date'),hsc($this->getParam('display')))); 40 } 41 } 42} 43