くんすとの備忘録

IT系技術メモ

移転しました。

15秒後に自動的にリダイレクトします。

【Play2.2】フィールドコンストラクタを改造してみた

組み込みの twitterBootstrapFieldConstructor.scala.html では help-block が邪魔になってきたので、それを外したものを作成しました。

play-2.2.0/framework/src/play/src/main/scala/views/helper/twitterBootstrap/twitterBootstrapFieldConstructor.scala.html を app/helpers/ へコピーして改造します。

使い方は

<!-- フィールドコンストラクタの上書き -->
@implicitField = @{ views.html.helper.FieldConstructor(helpers.html.myTwitterBootstrapFieldConstructor.render) }


<!-- フォームヘルパーの利用 -->
@helper.inputText(aForm("name"), '_label -> "ラベル")
組み込みのtwitterBootstrapFieldConstructorをimplicitした時のhtml
<div class="clearfix  " id="name_field">
    <label for="name">ラベル</label>
    <div class="input">
        
    <input type="text" id="name" name="name" value="" >

        <span class="help-inline"></span>
        <span class="help-block">Required</span> 
    </div>
</div>
自作のフィールドコンストラクタをimplicitした時のhtml
<div class="clearfix  " id="name_field">
    <label for="name">ラベル</label>
    <div class="input">
        
    <input type="text" id="name" name="name" value="" >

        <span class="help-inline"></span>
    </div>
</div>

これで「Required」が出なくなりました。