2016-06-13 36 views
1

的形式inputText的必要屬性我這是在HTML寫了一個輸入:如何設置在遊戲框架2.5.X

<input type="text" class="form-control" placeholder="Title..." name="title" id="title" maxlength="255" data-error="Title must not be empty" required> 

現在我想用Helper.inputText更換上面的輸入。這裏是我的代碼:

helper.inputText(postForm("title"), 'class -> "form-control", 'placeholder -> "Title...", 'name -> "title", 'maxlength -> 255, 
Symbol("data-error") -> "Title must not be empty") 

我不知道如何設置所需的屬性到inputText。 你有什麼想法嗎?謝謝!

回答

0

約束在後端模型中定義。如果您使用的是Java,它會像

public class User { 
    @Required 
    protected String title; 

    public void setTitle(String title) { 
     this.title= title; 
    } 

    public String getTitle() { 
     return title; 
    } 
} 

詳情:https://playframework.com/documentation/2.5.x/JavaForms#Defining-constraints

使用斯卡拉:

val userForm = Form(
    mapping(
    "title" -> nonEmptyText 
)(UserData.apply)(UserData.unapply) 
) 

詳情:https://playframework.com/documentation/2.5.x/ScalaForms#Defining-constraints-on-the-form

+0

我使用的是引導驗證,所以input元素必須具有「required」屬性才能顯示警告。我也在服務器端驗證數據,但在我的情況下,我只想在客戶端使用引導驗證,並向用戶顯示一些信息。 –

+0

如果你使用helper.inputText(postForm(「title」),'class - >「form-control」,'placeholder - >「Title ...」,'name - >「title」,'maxlength - > 255,符號(「數據錯誤」) - >「標題不能爲空」,「必需 - >」需要「)?我認爲價值並不重要,它只是需要屬性的存在。 –