i'm attempting add data- values on radio buttons within zf2. possible control each of inputs specified value_options?
a typical radio button added form:
$this->add(array( 'type' => 'radio', 'name' => 'duration', 'options' => array( 'value_options' => array( 'daily' => 'daily', 'weekly' => 'weekly', 'monthly' => 'monthly', ), ), )); ultimately, following, can specify individual parameters/options each radio item:
$this->add(array( 'type' => 'radio', 'name' => 'duration', 'options' => array( 'value_options' => array( array( 'attributes' => array( 'value' => 'daily', 'data-item' => 'apple' ), 'options' => array( 'label' => 'daily' ) ), array( 'attributes' => array( 'value' => 'weekly', 'data-item' => 'orange' ), 'options' => array( 'label' => 'weekly' ) ), array( 'attributes' => array( 'value' => 'monthly', 'data-item' => 'pear' ), 'options' => array( 'label' => 'monthly' ) ), ), ), )); my reason wanting above, want use javascript change upon selecting radio button, needs hold data attributes.
is possible yet?
it can done providing array (or object implements arrayaccess) instead of single value (almost wrote in example).
$this->add(array( 'type' => 'radio', 'name' => 'duration', 'options' => array( 'value_options' => array( 'daily' => array( 'label' => 'daily', 'value' => 'daily', 'attributes' => array( 'data-item' => 'apple', ), ), 'weekly' => array( 'label' => 'weekly', 'value' => 'weekly', 'attributes' => array( 'data-item' => 'orange', ), ), 'monthly' => array( 'label' => 'monthly', 'value' => 'monthly', 'attributes' => array( 'data-item' => 'pear', ), ), ), ), )); this should work on radios, multi-checkboxes & selects too.
Comments
Post a Comment