如何在 #after_build 中隐藏所需的 CCK Nodereference 输入小部件?
保存节点后,我想阻止用户编辑所需的节点引用字段。我尝试将类型更改为“nodereference_hidden”像这样,但提交将无法验证:该字段是必需的。
...所以我最终在字段配置 UI 中取消选中“必需”,并将其隐藏起来,如下所示:
$form['field_my_nodereference_field'][0]['#type'] = 'nodereference_value';< /code>
由于它作为值传递,因此没有理由丢失它,但我仍然觉得保留该字段为“必填”更安全。
Once the node has been saved once I'd like to block users from editing a required nodereference field. I tried changing the type to 'nodereference_hidden' like this but then submission won't validate: The field is required.
... So I ended up un-checking 'required' in the field configuration UI, and hiding it like so:
$form['field_my_nodereference_field'][0]['#type'] = 'nodereference_value';
Since it's passed as value there's no reason for it to be lost, still I'd have felt safer keeping the field 'required'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
drupal 的“必需”验证做了一些有趣的事情(删除 css、重置多阶段表单等等!),幸运的是,您可以添加自己的 hook_validate 函数来检查值,确保其正常,等等。添加一个红色星号,然后就到此为止了。
The drupal 'required' validation does some funny stuff (dropping css, resetting multi-stage forms, and more!), luckily you can add your own hook_validate function that checks for the value, makes sure it's sane, and so forth. Add a red asterisk and call it a day.