Symfony2 JS更新表单区域

时间:2014-06-17 11:33:36

标签: javascript symfony

我做了一个表格,并有实体 我想制作,依赖于下拉选择显示一个实体的不同形式样式

例如在JS

var firsttype=<div class="form-row form-group">
    <div class="col-sm-3 col-md-3">
        {{ form_label(form.line1, "Passport Line 1", {"label_attr": {"class": "control-label"} }) }}
    </div>            
    <div class="col-sm-3 col-md-3 controls">
        {{ form_errors(form.line1) }}
        {{ form_widget(form.line1) }}
    </div>
</div>
<div class="form-row form-group ">
    <div class="col-sm-3 col-md-3">
        {{ form_label(form.line2, "Passport Line 2", {"label_attr": {"class": "control-label"} }) }}
    </div>
    <div class="col-sm-3 col-md-3 controls">
        {{ form_errors(form.line2) }}
        {{ form_widget(form.line2) }}
    </div>
</div>
<div class="form-row form-group ">
    <div class="col-sm-3 col-md-3">
        {{ form_label(form.nameOnDocument, "Name on Document", {"label_attr": {"class": "control-label"} }) }}
    </div>
    <div class="col-sm-3 col-md-3 controls">
        {{ form_errors(form.nameOnDocument) }}
        {{ form_widget(form.nameOnDocument, {"attr" : { "class": "form-control"} }) }}
    </div>
    <div class="col-sm-3 col-md-2 col-md-offset-1">
        {{ form_label(form.expireDate, "Expiry Date", {"label_attr": {"class": "control-label"} }) }}
    </div>
    <div class="col-sm-3 col-md-3 controls">
        {{ form_errors(form.expireDate) }}
        {{ form_widget(form.expireDate, {"attr" : { "class": "form-control" } }) }}
    </div>              
</div>

这种不同的风格和改变形式的不同风格,取决于下拉列表

$('.form_type').html(firsttype);

因为如果选择1,你需要感受所有信息,如果选择2,只需添加简单信息

0 个答案:

没有答案