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

sah*_*hil 4 forms web2py

替代文字

我使用以下代码在附加图像中生成表单.是否可以更改表单中字段的大小.我想减小估计时间的输入字段的大小和它右侧的保管箱字段

{{=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}}
Run Code Online (Sandbox Code Playgroud)

mdi*_*rro 5

是.你可以而且有很多方法.

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

input[name=estimate_time] { width:50px }
Run Code Online (Sandbox Code Playgroud)

同样你可以使用JS/jQuery(我建议你在视图中这样做).

jQuery(document).ready(function(){ jQuery('input[name=estimate_time]').css('width','50px');});
Run Code Online (Sandbox Code Playgroud)

您还可以在控制器中的python中使用类似jQuery的语法:

form.element('input[name=estimate_time]')['_style']='width:50px'
Run Code Online (Sandbox Code Playgroud)