Chosen.js不返回php中的选定选项

时间:2016-05-17 15:14:56

标签: javascript php jquery php-5.3 jquery-chosen

我安装在我的dev chosen.js库中。我的PHP代码:

$this->form_add_offer = new Form\Form(
        new Form\Field\Text('name', '', true),
        new Form\Field\Select('orders','',true, $a_offer_group)
    );
    if ($this->getRequest()->isPostMethod() && $this->form_add_offer->bind($_POST)) {
       print_r($this->form_add_offer->orders->getValue()) 
    }

我的观点:

<form id="form_add_offer" action="{{ 'route'|url_route }}" method="post" >
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="col-xs-6 col-sm-6 col-md-6">
                <div class="form-group">
                    <label class="control-label" for="" style="display: block;font-size: 100%;margin: 0;width: 12em;padding: 5px;">Nom : </label>
                    <input type="text" id="{{ form_add_offer.name.name }}" name="{{ form_add_offer.name.name }}" value="{{ form_add_offer.name.value }}" required="required" placeholder="Nom" class="form-control"  style="display: block;font-size: 100%;margin: 0;padding-left: 5px;"/>
                </div>
               <div class="form-group">
                    <label class="control-label" for="{{ form_add_offer.orders.name }}" >Type : </label>
                    <div>
                        <select data-placeholder=""
                                style="width:350px;"
                                class="chosen-select form-control {{ form_add_offer.orders.name }}" multiple
                                tabindex="6"
                                id="{{ form_add_offer.orders.name }}">
                            {% for key,optogroup in form_add_offer.orders.choices %}
                            <optgroup label="{{ key }}">
                                {% for k,v in optogroup %}
                                    <option value="{{ key }}"
                                            {% if k == form_add_offer.orders.value %}selected="selected"{% endif %}>
                                        {{ v }}
                                    </option>
                                {% endfor %}
                            </optgroup>
                            {% endfor %}
                        </select>
                    </div>
                </div>

视图中的.js:

<script>
    $(document).ready(function() {
        var config = {
            '.chosen-select'           : {},
            '.chosen-select-deselect'  : {allow_single_deselect:true},
            '.chosen-select-no-single' : {disable_search_threshold:10},
            '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
            '.chosen-select-width'     : {width:"95%"}
        }
        console.log(config);
        for (var selector in config) {
            $(selector).chosen(config[selector]);
        }
    });

</script>

多选框工作正常,问题出在我提交表单时,例如,如果我$this->form_add_offer->name->getValue(),我从输入文本name获取值。如果我$this->form_add_offer->orders->getValue()所以我得到空数组,但视图中的多选框不为空。你能帮我吗 ? Thx提前和抱歉我的英语

0 个答案:

没有答案