开发者

How do I hide a required CCK Nodereference input widget in #after_build?

Once the node has been saved once I'd like to block users from editing a required node开发者_开发问答reference 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'.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜