使用field.custom.widget创建的表单字段如何自定义大小

4

alt text

我使用以下代码生成了一个表单,如上图所示。 是否有可能改变表单中字段的大小? 我想要减小“预计时间”输入字段的大小以及其右侧的下拉框字段。

{{=form.custom.begin}}
<table>

<table><tr>
<td><b>Type :</b></td><td><div>{{=form.custom.widget.type}}</div></td>
</tr><tr>
<td><b>Title :</b></td><td><div>{{=form.custom.widget.title}}</div></td>
</tr><tr>
<td><b>Description :</b></td><td><div>{{=form.custom.widget.description}}</div></td>
</tr><tr>
<td><b>Estimated Time :</b></td><div'><td>{{=form.custom.widget.estimated_time}}{{=form.custom.widget.estimated_time_unit}}</td> </div>
</tr>
<tr>
<td></td><td><div align='center'>{{=form.custom.submit}}</div></td>
</tr>
</table>

{{=form.custom.end}}
1个回答

5

可以的,有很多种方法。

推荐的方法是查看生成的JS。您会发现它遵循书中描述的命名约定。您可以使用CSS来改变每个小部件的外观和感觉。

input[name=estimate_time] { width:50px }

同样地,您可以使用JS/jQuery(我建议您在视图中这样做)。
jQuery(document).ready(function(){ jQuery('input[name=estimate_time]').css('width','50px');});

您可以在控制器中使用类似于jQuery的语法来编写Python代码:
form.element('input[name=estimate_time]')['_style']='width:50px'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接