I'm trying to prepopulate/assign values on a node edit form for multigroup fields but it seems it doesn't work. I have a hook_form_alter where if I assign a values for a normal (not multigroupped) text field it works but for a textfield in a multigroup it doesn't seem to work.
I've attached a module for exemplification purposes. You just have to enable the module: it will automatically create a multigroup_prepop content type with 2 textfields. The module will also create a multigroup_prepop node type and it will display a message so you can easily locate the node. When you go the the edit page of the created node you'll see that the standalone textfield is assigned a value but it won't work for the multigroupped textfield.
Of course, for it to work it requires CCK 6.x-3.x-dev branch.
Thanks,
Andrei
Am I doing something wrong here or is it a multigroup/cck bug?
| Comment | File | Size | Author |
|---|---|---|---|
| multigroup_prepop.tar_.gz | 1.78 KB | andreiashu |
Comments
Comment #1
markus_petrux commentedYour module needs to load after the fieldgroup module (changing the weight column in {system} table). To see why, we need to explore how the node form is built:
So, if you want to alter the field related elements in a multigroup, your module needs a weight higher than the one used by the fieldgroup module. In that way, your hook_form_alter() will be able to find the form with all the changes the fieldgroup + multigroup did already in place.
Comment #2
andreiashu commentedHi Markus,
Thank you very much for the detailed explanation.
I changed the weight of my custorm module to something > 9 and everything works as expected now.
Thanks!
Comment #4
seancorrales commentedJust wanted to say thanks for sharing not only how to do this, but why it works this way. This saved me a lot of agony! :)
-Sean
Comment #5
Josephnewyork commentedGood to know!
Comment #6
dafederFYI folks working on this issue, I was NOT able to set multiple default values for multigrouped fields via hook_form_alter. However, I WAS finally able to do it by setting the field's values with hook_nodeapi() on $op == prepare.