Score:0

Clear field value when edit node

mh flag

I have a List (text) field in a content type that will determine the importance of the content whether it is Major or Minor and that field is set to be required. I need to force content editors to make that selection each time they edit a content page. Is there a way to clear the data from that field upon edit event?

Note: I'm on Drupal 9.2.18

Hodba Khalaf avatar
eg flag
If I got it right, HOOK_form_alter should be ok, then set the field[YOURFIELD]['default_value'] = NULL;
Lambic avatar
ph flag
Remember to specify which version of Drupal you're using.
Fareed Fattal avatar
mh flag
@HodbaKhalaf. The hook_form_alter worked only the NULL value was rejected so I replaced it ' ' and that solved the issue. Thanks!
Fareed Fattal avatar
mh flag
@Lambic Sorry for not specifying Drupal version, it's 9.2.x.
Score:1
eg flag

HOOK_form_alter should be ok, then empty the field default value.

$form[YOURFIELD]['default_value'] = '';
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.