2015-05-27 33 views
0

我有conf目錄下的播放框架。CSS到播放框架中的conf/messages

required.message=This field cannot be empty 

和模型中,我有:

@Constraints.Required(message = "required.message") 
public String name; 

我得到正確驗證上的消息。我想要做的是改變消息的顏色。目前,我得到如下:

enter image description here

我要留言「此字段不能爲空」是在紅色。

編輯:

查看代碼

@(customerForm : Form[Customer]) 

<link rel="stylesheet" media="screen" href="@routes.Assets.at("css/bootstrap.min.css")"> 
<script src="@routes.Assets.at("js/bootstrap.min.js")" type="text/javascript"></script> 
@main("Customer information") { 
    <h2 style="margin-left: 5%">Customer Information</h2> 
    @helper.form(action = routes.Customers.save()) { 
     <fieldset style="margin-left: 5%"> 
      <legend>Adding new customer</legend> 
      @helper.inputText(customerForm.field("Id"), '_label -> null,'placeholder->"Id") 
      @helper.inputText(customerForm.field("name"), '_label -> null, 'placeholder->"Name", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("address"), '_label -> null, 'placeholder->"Address", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("city"), '_label -> null, 'placeholder->"City", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("state"), '_label -> null, 'placeholder->"State", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("postcode"), '_label -> null, 'placeholder->"Postcode", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("phone"), '_label -> null, 'placeholder->"Phone number", '_showConstraints -> false) 
      @helper.inputText(customerForm.field("email"), '_label -> null, 'placeholder->"Email", '_showConstraints -> false) 
     </fieldset> 
     <input class="btn btn-success" style="margin-left: 5%" type="submit" value="Save"/> 
     <input class="btn btn-danger" style="margin-left: 5%" onClick="window.location='@routes.Customers.list()';" type="button" value="Cancel"/> 
    } 
} 

謝謝!

+0

你可以發佈你的視圖代碼的形式? –

+0

@DanielOlszewski查看編輯過的文章 – Nabin

回答

1

您應該將所需樣式添加到您的CSS樣式表並創建一個自定義表單助手來滿足您的需求。

這裏是一個自定義customInputText.scala.html文件基礎上,docs的最簡單的例子:

@(elements: helper.FieldElements) 

<div> 
    <label for="@elements.id">@elements.label</label> 
    <div> 
     @elements.input 
     <span class="errors">@elements.errors.mkString(", ")</span> 
    </div> 
</div> 

而在你的CSS文件,你可以有這樣的事情:

.errors { 
    color: red; 
} 

接下來,您應該將新創建的字段構造函數添加到窗體中的視圖中的所有導入旁邊,以便它可以自動使用。表單本身不需要更改。它會挑選隱含的構造:

@implicitField = @{ FieldConstructor(myFieldConstructorTemplate.f) } 

通過創建一個自定義字段的構造函數,你可以在整個應用程序重複使用。

+0

您之前試過嗎?你確定這是我需要的嗎?謝謝你的回答 – Nabin

+0

我已經在幾個項目中成功完成了它,如果你使用表單助手,那麼這是減少代碼重複的最好方法。我看到你正在使用Bootstrap,所以你可能有興趣基於它的API創建這個輸入。 –