Input Fill in Play Framework

Trying to pass in a value for input in a form does not seem to produce any results. The documentation for auxiliary input Text shows a value parameter as part of creating the input, but I'm not sure how to pass the required parameters to the constructor.

I pass the parameters as follows:

@inputText(accountForm("accountName"), args = '_label -> "Account Name: ", '_value -> "Test") 
+6
source share
2 answers

The value parameter that you see in the inputText belongs to the Field class. If you want to specify your default value, you must set the value in your controller. You can set default values ​​using the fill method of the Form class.

Note. There is also an HTML5 placeholder attribute. You can pass this attribute using inputText helper: @inputText(accountForm("accountName"), 'placeholder -> "Test")

+7
source

You can populate the Form class as suggested by Li-o, or you can override the form value in the template itself like this. This will set the value to "Test" or the value to "variable".

 @inputText(accountForm("accountName").copy(value=Some("Test")), args = '_label -> "Account Name: ") @inputText(accountForm("accountName").copy(value=Some(variable)), args = '_label -> "Account Name: ") 
+11
source

Source: https://habr.com/ru/post/913737/


All Articles