Is there a way to add or change a class to a form wrapper (the div's) using the form api?
Or is that just done with the theme function ?
If so which theme function is used to change that?
欢迎各位兄弟 发布技术文章
这里的技术是共享的
10 1 | |||||||||||||||||
|
5 | You can override
| ||||||||||||||||
|
3 | I know this is a super old thread, but I'v been learning how to alter form elements and add classes. I got around to making a custom module:
| ||||
|
3 | To Change the "wrapper" you need to override form_element. Basically all form elements get rendered with the form_element theme So to change how this renders your form elements you simply copy that function to your template.php folder and rename it to: now you can make any changes and they will be used instead of the original function
| |||
0 | Importantly, theme_form_element will only modify the direct parent wrapper div and this may not be the intended target for CSS effects. [Although not programmatic, if one simply wants to apply a class to a node field's top-wrapper (it's wrapper's, wrapper's, wrapper) one can I suppose use "Field group" module by selecting "Manage Fields" for a particular content type and select "Add new group" as a simple DIV. Then the label can be removed and desired classes assigned to the additional wrapper (but now we have even more wrappers) - with unlimited nesting] | ||
0 | You could use
and this will wrap it around | ||
0 | Make wrapper attributes configurable! Create your own form-element theme function in your theme...
Then you can do stuff like this...
| ||
0 | There are come cases in which neither The normal outermost div is just
which is difficult to target in CSS. I can target The solution I came up with is to add a
And here's the
Relying on string substitution isn't very portable, so use
|
10 1 | |||||||||||||||||
5 | 您可以覆盖
| ||||||||||||||||
3 | 我知道这是一个超老线程,但我一直在学习如何改变表单元素和添加类。我做了一个自定义模块:
| ||||
3 | 要更改“包装器”,您需要覆盖form_element。基本上所有的表单元素得到呈现与form_element主题 所以要改变这种渲染表单元素的方式,只需将该函数复制到template.php文件夹,并将其重命名为: 现在你可以进行任何更改,他们将被使用,而不是原始的功能
| |||
0 | 重要的是,theme_form_element将只修改直接父包装器div,这可能不是CSS效果的预期目标。 [虽然不是程序化的,如果只是想要将一个类应用到一个节点字段的顶层封装器(它的包装器,包装器,包装器),我可以假设使用“字段组”模块通过选择“管理字段”为特定的内容类型,选择“添加新组”作为一个简单的DIV。然后可以删除标签,并将所需的类分配给附加包装器(但现在我们还有更多的包装器) - 具有无限嵌套] | ||
0 | 你可以使用
这将包装它 | ||
0 | 使包装器属性可配置! 在您的主题中创建自己的表单元素主题函数...
然后你可以做这样的东西...
| ||
0 | 有来的情况,即既不 正常最外面的div就是
这是很难在CSS中的目标。我可以指定 我想出了解决的办法就是添加一个
而这里的
依托字符串替换不是很便携,所以使用
| ||
-1 |
你可以使用上面的方法在表单元素上添加一个类。 | ||