ZF2:我可以将文本框附加到multicheckbox吗?如何使用MultiCheckbox或ZF2中的复选框组创建“其他”或“注释”之类的文本框字段?

vlr

我正在遵循此示例,但是我需要向“其他”选项添加一个附加文本框,该文本框在单击“其他”复选框时将被激活。我可以在表单中添加一个单独的文本框,并通过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);
    }

}
vlr

我是这样完成的:

 $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);
   });

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档