php - How add custom attribute in zend framework 2 using zend from -
i want use angularjs in zend framework project , in project forms generated using zend form. how can add angular directive such "ng-model" in form elements whenever trying add custom attribute in zend-form elements (input, select etc) in view not getting attribute ----
here lead form
class leadform extends form {
public function __construct() { parent::__construct('lead_form'); $this->setattributes(array( 'action' => '', 'method' => 'post', 'name' => 'lead_form', 'id' => 'lead_form', 'class' => 'smart-form', 'role' => 'form', 'novalidate' => 'novalidate' )); $this->add(array( 'name' => 'first_name', 'type' => 'text', 'options' => array( 'label' => 'first name', ), 'attributes' => array( 'class' => 'form-control validate[required,custom[onlylettersp]]', 'placeholder' => 'first name', **'ng-model' => "first_name", // attribute not generating in view** ), )); }
}
here controller calling form , send view displaying
$createleadform = new \admin\form\leadform(); return new viewmodel(array( 'form' => $createleadform, ));
here code in view showing element
<?php echo $this->forminput($this->form->get('first_name')); ?>
but after prinnting form element getting see no "ng-model" in input element
<input type="text" value="" placeholder="first name" class="form-control validate[required,custom[onlylettersp]]" name="first_name" >
i have set 1 attribute "ng-model " attribute not appearing in view
i want element (using zend form ) -
<input type="text" ng-model="first_name" value="" placeholder="first name" class="form-control validate[required,custom[onlylettersp]]" name="first_name" >
how can using zend form , need change in form , why can not able add custom attribute? please me.
thanks in advance
you can use data-ng-*:
$this->add(array( // ... 'attributes' => array( // ... 'data-ng-model' => 'first_name', ), ));
Comments
Post a Comment