I’m trying to create a dijit button in ZF. I’ve tried using plain dojo and it works, but when using Zend_Dojo it creates a simple button, in other words, Zend_Dojo_Form_Elements acts as Zend_Form_Element.
IndexController without Zend_Dojo (this way the button is render properly):
$newEventButton = new Zend_Form_Element_Button('newEvent', array('dijitType'=>'dijit.form.Button');
$newEventButton->setLabel('New Event');
$this->view->newEventButton = $newEventButton;
IndexController with Zend_Dojo (this way it creates a simple button as it can be seen bellow):
$newEventButton = new Zend_Dojo_Form_Element_Button('newEvent');
$newEventButton->setLabel('New Event');
$this->view->newEventButton = $newEventButton;
And the result is:
enter code here
<button type="button" id="newEvent" name="newEvent">New event</button>
What am I doing wrong, why the Zend_Dojo_Form_Element acts as Zend_Form_Element? Thanks.
If you just want to create a button, directly use a view helper (Zend_Dojo_View_Helper_Button) instead of using a form element (Zend_Dojo_Form_Element_Button). Before doing this, make sure you include the dojo view helpers in your bootstrap:
And make sure you enable Dojo view helper in your view or layout:
Now, to directly use the view helper (Zend_Dojo_View_Helper_Button) to render your button (bypassing Zend_Dojo_Form_Element_Button, which you should use only when building a complete form). In your view:
Or if you want to define the button in the controller:
And then render it in the view:
Hope it helps!