web2py自动完成窗口小部件不“对CSS友好"吗? [英] web2py autocomplete widget not "CSS-friendly"?
问题描述
在模型中:
db.define_table('mytable',
Field('auto'),
Field('manual')
)
db.mytable.auto.widget=SQLFORM.widgets.autocomplete(request,db.mytable.auto)
在控制器中:
def index():
form = SQLFORM(db.mytable)
return locals()
结果:具有自动完成功能的字段看起来很烂,就像没有任何CSS样式一样,而另一个字段看起来不错.
Result: The field with autocomplete looks shitty like it doesn't get any CSS-styling, while the other field looks nice.
此处,我可以在控制器中进行操作:
As descibed here I can do in the controller:
form.custom.widget['auto'][0].add_class('form-control')
这也使自动完成字段看起来不错.
Which makes the autocompleted field look nice, too.
但是,自动完成小部件提供与其他输入字段相同的CSS友好标签不是正常行为吗? 还是我做错了什么?
But shouldn't it be normal behaviour for the autocomplete widget to provide the same CSS-friendly tags as other input fields? Or have I done something wrong?
推荐答案
Bootstrap 3 formstyle
函数(在web2py脚手架应用程序中是默认的formstyle
)不能正确设置自动填充小部件的样式(应更正此样式) ).
The Bootstrap 3 formstyle
function (which is the default formstyle
in the web2py scaffolding application) does not properly style the autocomplete widget (this should be corrected).
作为一种解决方法,如果您希望样式影响从DAL模型生成的所有表单,则还可以执行以下操作:
As a workaround, if you want the styling to affect all forms generated from the DAL model, you can also do this:
autocomplete = SQLFORM.widgets.autocomplete
db.mytable.auto.widget = \
lambda f, v: autocomplete(request, db.mytable.auto)(f, v, _class='form-control')
或者制作专门的Bootstrap自动完成小部件以用于任何字段,您可以执行以下操作:
Or to make a specialized Bootstrap autocomplete widget for use with any field, you can do:
def bootstrap_autocomplete(*args, **kwargs):
widget = SQLFORM.widgets.autocomplete(*args, **kwargs)
return lambda f, v: widget(f, v, _class='form-control')
然后,在定义模型时,您可以执行以下操作:
Then when defining a model, you can do:
db.mytable.auto.widget = bootstrap_autocomplete(request, db.mytable.auto)
更新:自动完成小部件已得到修复-与其他表单小部件一样,它现在使用了formstyle
指定的样式.因此,不再需要上述解决方法.
UPDATE: The autocomplete widget has been fixed -- it now uses the styling specified by formstyle
, as with other form widgets. So, the above workaround should no longer be needed.
这篇关于web2py自动完成窗口小部件不“对CSS友好"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!