ZF2: Могу ли я прикрепить текстовое поле к мультиполе? Как создать поле для ввода текста, например & quot; Другое & quot; или & quot; Комментарий & quot; с MultiCheckbox или группой флажков в ZF2?

Я слежу за этим пример, но мне нужно добавить дополнительное текстовое поле в опцию «Другое», которая активируется при нажатии кнопки «Другое». Я могу добавить отдельное текстовое поле в форму и включить его с помощью кода JS, но как мне сгруппировать его вместе со значениями MultiCheckbox или группы флажков для определенного свойства определенного target_class?

форма

class FieldEducationAssignmentsForm extends Form
{
/**
* @var EntityManager
*/
protected $em;

public function __construct($name = null)
{
parent::__construct('Field Education Assignments');

$this->setAttribute('method', 'post');

$this->add(array(
'name' => 'id',
//'type' => 'Hidden',
'options' => array(
'label' => 'Id',
),

));

$this->add(array(
'type' => 'Hidden',
'name' => 'buildName',
'attributes' => array(
'value' => 'unknown'
)
));

$this->add(array(
'type' => 'Zend\Form\Element\MultiCheckbox',
'name' => 'directPractice',
'options' => array(
'label' => 'A. Check all direct practice field education assignments',
'object_manager' => $this->getEntityManager(),
'target_class' => ' OnlineFieldEvaluation\Entity\FieldEducationAssignments', //'YOUR ENTITY NAMESPACE'
'property' => 'directPractice', //'your db collumn name'
'empty_option' => '--- please choose ---',
'value_options' => array(
'1' => 'Adults',
'2' => 'Individuals',
'3' => 'Information and Referral',
'4' => 'Families',
'5' => 'Advocacy',
'6' => 'Treatment Planning',
'7' => 'Children',
'8' => 'Groups',
'9' => 'Community Networking Linkages',
'10' => 'Adolescents',
'11' => 'Couples',
'12' => 'Case Management',
'13' => 'Discharge Planning',
'14' => 'Diagnostic Assessment',
'15' => 'Older Adults',
'16' => 'Psychosocial Assessment',
'17' => 'Short Term Intervention',
'18' => 'Crisis Intervention',
'19' => 'Long Term Intervention',
'20' => 'Inter/Multidisciplinary Team Meetings',
'21' => 'Other (specify)'
),
),
'attributes' => array(
'value' => '1', //set checked to '1'
'multiple' => true,
)
));

$this->add(array(
'name' => 'otherDirectPracticeTxt',
'type' => 'Text',
'attributes' => array(
'disabled' => 'disabled',
),
));

...
}

сущность

<?php

namespace OnlineFieldEvaluation\Entity;

// Add these import statements
use Doctrine\ORM\Mapping as ORM;

/**
* General Time Management.
*
* @ORM\Entity
* @ORM\Table(name="form_general_time_management")
*
**/
class FieldEducationAssignments{

/**
* @ORM\id
* @ORM\Column(type="integer");
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\Column(type="integer");
*/
protected $studEvalId;
/**
* @ORM\Column(type="string", length=1000)
*/
protected $directPractice;

/**
* @param mixed $directPractice
*/
public function setDirectPractice($directPractice)
{
$this->directPractice = $directPractice;
}

/**
* @return mixed
*/
public function getDirectPractice()
{
return $this->directPractice;
}

/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}

/**
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* @param mixed $studEvalId
*/
public function setStudEvalId($studEvalId)
{
$this->studEvalId = $studEvalId;
}

/**
* @return mixed
*/
public function getStudEvalId()
{
return $this->studEvalId;
}/**
* Magic getter to expose protected properties.
*
* @param string $property
* @return mixed
*/
public function __get($property)
{
return $this->$property;
}

/**
* Magic setter to save protected properties.
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value)
{
$this->$property = $value;
}/**
* Convert the object to an array.
*
* @return array
*/
public function getArrayCopy()
{
return get_object_vars($this);
}

}

1

Решение

Я сделал это так:

 $this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',

'name' => 'directPractice',

'options' => array(
'label' => 'A. Check all direct practice field education assignments',
'label_attributes' => array(
'class' => 'label-multicheckbox-group'
),

'required' => false,
'allow_empty' => true,
'continue_if_empty' => false,

'object_manager' => $this->getObjectManager(),
'target_class' => 'OnlineFieldEvaluation\Entity\FieldEducationAssignments', //'YOUR ENTITY NAMESPACE'
'property' => 'directPractice', //'your db collumn name'
'disable_inarray_validator' => true,
'value_options' => array(
'1' => 'Adults',
'2' => 'Individuals',
'3' => 'Information and Referral',
'4' => 'Families',
array(
'value' => 'Other',
'label' => 'Other (specify)',
'label_attributes' => array(
'class' => 'bindto',
'data-bindit_id' => 'otherDirectPracticeTxt_ID'
),
'attributes' => array(
'id' => 'otherDirectPractice_ID',
),
)
),
),
'attributes' => array(
'value' => '1', //set checked to '1'
'multiple' => true,

)
));

$this->add(array(
'name' => 'otherDirectPracticeTxt',
'type' => 'Text',
'attributes' => array(
'id' => 'otherDirectPracticeTxt_ID',
'disabled' => 'disabled',
),
));

JQuery

    $(".bindto").each(function(){
debugger;
var binditId = $(this).attr("data-bindit_id");
var $txtBoxToBind = $(this.form).find('input[id=' + binditId + ']');
$(this).after($txtBoxToBind);
});
0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]