在 Grails 中,您可以使用<f:all bean="beanName" />. 虽然生成的表单看起来很棒,但我想知道是否有可能在该字段中有一个占位符,以便结果变成这样:
<input type="text" name="question" placeholder="type your question here" />
Run Code Online (Sandbox Code Playgroud)
我尝试在 Grails 中使用属性验证,如下所示:
class Question {
static constraints = {
question(size:5..100, attributes:[placeholder:"type your question here"])
}
}
Run Code Online (Sandbox Code Playgroud)
但它似乎对生成的 HTML 没有任何影响。
以防万一有任何混淆,f:all标签由字段插件提供。我认为没有任何方法可以placeholder通过域类约束来指定属性,但还有一些其他选项。
一种选择是为此属性定义自定义 (GSP) 模板并在其中指定占位符属性。此模板的路径取决于您使用的插件版本,但您可以在此处找到详细信息。
或者,如果您f:field使用单独呈现每个字段,而不是使用f:all您可以将其他属性传递给输入字段,例如
<f:field bean="person" property="gender"
widget-placeholder="type your question here"/>
Run Code Online (Sandbox Code Playgroud)
在插件的早期版本(1.5 之前)中,属性应该被命名input-placeholder,例如
<f:field bean="person" property="gender"
input-placeholder="type your question here"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1182 次 |
| 最近记录: |