的Zend和jQuery的DatePicker产生意外结果
问题描述:
我有一个Zend形式,我已通过启用jQuery的组件:的Zend和jQuery的DatePicker产生意外结果
ZendX_JQuery::enableForm($this);
,然后加入几个非jQuery的元件,并且一个jQuery的DatePicker的,其定义为:
$testing = new ZendX_JQuery_Form_Element_DatePicker('dp1', array('jQueryParams' => array('dateFormat' => 'yy-mm-dd')));
$testing->setLabel('Date of Birth 2')
->setRequired(true)
->addValidator('NotEmpty');
然后我设置的装饰如下(第一对所有的元素,然后更换为的DatePicker装饰者定义):
$this->clearDecorators();
$this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => 'div', 'class'=>'form-block'))
->addDecorator('Form');
$this->setElementDecorators(array(
array('ViewHelper'),
array('Errors'),
array('Description', array('tag' => 'div', 'class' => 'tooltip')),
array('Label', array('separator'=>' ')),
array('HtmlTag', array('tag' => 'div', 'class'=>'element-block')),
));
$formJQueryElements = array(
array('UiWidgetElement', array('tag' => '')),
array('Errors'),
array('Description', array('tag' => 'div', 'class' => 'tooltip')),
array('Label', array('separator' => ' ')),
array('HtmlTag', array('tag' => 'div', 'class' => 'element-block')),
);
$this->getElement('dp1')->clearDecorators();
$this->getElement('dp1')->setDecorators($formJQueryElements);
这似乎正确显示所有我的领域,除了DatePicker,它已被转换成文本字段。该字段的HTML看起来像:
<div class="element-block">
<label for="dp1" class="required">Date of Birth 2</label>
<input type="text" name="dp1" id="dp1" value="">
</div>
它不是DatePicker。我在设置时错过了什么,或者我在这里做了什么错误?
非常感谢。
答
找到答案,至少部分。我忘了,包括在我看来,下面的代码,这意味着该领域没有得到转换成日期字段:
<script>
$(function() {
$("#dp1").datepicker();
});
</script>
这改变了文本字段成一个datepicker。但是这并没有保留在Form类中设置的任何jQuery选项,这意味着我必须在这里设置它们,这只有在网站上的所有日期选择器使用相同的规则来显示(它们不会)的情况下才会起作用,并且我必须改变使用ID来使用元素的类,这不是什么大问题。