Score:0

Webform composite sub-element altering : how to do?

za flag

I'm currently developing a Webform based module (D9). One functionality I'm working on is around form "interdependency" : for a given form, some fields can be pre-filled from another webform submission of the same user. The hard part is tat I want to prevent end-user editing the prefilled data; I'm think about / testing multiples options :

  1. Simply add #disabled property to each prefilled fields : not good because disabled field values are NOT submitted
  2. Simply add #readonly property to each prefilled fields : not good because some field cannot be "readonly" such as select (and readonly attribute can be easily removed by end-user)
  3. Do not "write protect" pre-filled fields, but override all prefilled fields juste before entity saving (entity presave maybe ?) with initial data values
  4. Alter each-prefilled field to transform them to textfield, or markup + hidden field

For about all those options I need to be able to alter the custom composite fields, and theirs values (multivalues custom composite field). For now, I'm able to loop over the custom composite structure ($form['elements']['my_composite_field']['#element']['my_composite_subfield']) in classic hook_form_alter ; but I don't know how to alter my_composite_subfield fields individually (because pre-filled fields must be altered, unlike any new item added by user (native "add more item" ajax button).

Can you please help ? Which hook can be used ? Or maybe a Webform custom handler ?

Thanks

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.