2

如何将 myForm 中名为“isMarried”的字段绑定到视图中的复选框控件?我想要这种双向绑定。我正在使用来自https://github.com/nostalgiaz/bootstrap-switch的引导开关

@(myForm: Form[_])
@helper.form(action = controllers.index.submit, 'id -> "myForm") {

<fieldset>
<legend>General information</legend>
<div class="twipsies well">
   <div class="control-group">
        <label class="control-label" for="isMarried">Married</label>
        <div class="controls">
            <div class="switch switch-small" tabindex="0" data-on-label="Yes" data-off-label="No" data-off="warning">
                <input id="isMarried" name="isMarried" type="checkbox"/>
            </div>
        </div>
    </div>

</div>

</fieldset>
}
4

2 回答 2

4

我没有使用复选框(在支付中),但我会使用复选框助手:

例子:

@checkbox(field = myForm("done"))

见源:https ://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/views/helper/checkbox.scala.html

如果您需要自定义 HTML 以满足您的需求,请编写您自己的帮助程序/标签:

祝你好运!

于 2013-03-23T00:08:15.100 回答
0

型号为:

/**

 * This class represent a school model 

 * @author Giovanni Alberto García

 * @version 1.0

 */

@Entity

public class School extends Model {


  @Id

  @Column(unique=true, nullable=false)

  public Long id;


  @ManyToMany(cascade = CascadeType.ALL)

  public List<User> members;


  public boolean rElecCFE;

...

}

如您所见, rElecCFE 是布尔值,因此视图是:

@(schoolForm: Form[School])(schoolId: Long)

@import helper._ 

@main("Completar registro") {

<div id="edition">

  @form(action=routes.Nama.doEdit()) {
  <fieldset id="registration-electicity">
    <input type="hidden" name="id" value="@schoolId"/>
    <legend>Electricidad</legend>
    @checkbox(schoolForm("rElecCFE"),
    '_showConstraints->false,
    '_disabled->""
    )
...
  }
</div>
}
于 2014-12-04T19:53:57.347 回答