Zend form bootstrap annotation datepicker “Object

2019-02-28 15:55发布

I'm using Zend framework with Bootstrap and ReverseForm adapter, and have an interesting problem with it: when I use Bootstrap Datepicker in Zend Form I've the next exception:

Object provided to Escape helper, but flags do not allow recursion

There is my code of formfield:

use \Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use \Zend\Form\Annotation as ZFA;

...

/**
 * @var \DateTime
 *
 * @ODM\Date
 *
 * @ZFA\Type("ReverseForm\Element\BootstrapDatepicker")
 * @ZFA\Attributes({"type":"text"})
 * @ZFA\Options({
 *      "label":"Date",
 *      "extended": {
 *          "help": {"content": ""},
 *      }
 * })
 *
 */
private $date;

and there is my reverse form config:

'ReverseForm\Element\BootstrapDatepicker' => array(
    'js' => array(
        '/vendor/datepicker/js/bootstrap-datepicker.js'
    ),
    'css' => array(
        '/vendor/datepicker/css/datepicker.css'
    ),
    'template' => 'input.phtml',
    'inlineJs' => "$('#%1\$s').datepicker(%2\$s);",
    'inlineJsConfig' => array(
        'format' => 'dd.mm.yyyy',
        'weekstart' => new \Zend\Json\Expr(1),
    )
),

Where I have a mistake?

4条回答
虎瘦雄心在
2楼-- · 2019-02-28 16:23

I had the same issue. Changing the input's type from text to date should fix your problem. (https://github.com/zendframework/zf2/issues/3724)

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-28 16:26

Its a similar issue to the one you get if you do not add the type field to the Zend Form:

'type' => 'Zend\Form\Element\Time',

The whole element is as such::

   $this->add(array(
    'name' => 'officialDrawTime',
        'type' => 'Zend\Form\Element\Time',
        'attributes' => array(
            'required' => 'required',
            'type'   => 'time',
            'class' => 'form-control input-large',
            'placeholder' => 'e.g 19:30 or 07:30 (24 hour clock)',
            'pattern' => '^[0-9]{2}:[0-9]{2}$'
        ),
        'options' => array(
            'label' => 'Official draw time',
            'instructions' => 'The official draw time...)'
        ),
    ));
查看更多
别忘想泡老子
4楼-- · 2019-02-28 16:28

This works for me.
The value convert to date format will solve the issue.
In your controller: write:

$users['usrBirthday']=$user->getBirthday()->format('d-m-Y');
$form->setData($users);
$form->bind($user);     
查看更多
地球回转人心会变
5楼-- · 2019-02-28 16:36

No the mistake apparently came from your code or maybe the point is you have to do if is an editAction not just bind but add:

$form->bind($document);
$form->get('datenais')->setValue($document->getDatenais()->format('Y-m-d'));

I know not the clean way but it will solve your problem. If your find another way i'll glad to see your piece of code.

查看更多
登录 后发表回答