Score:0

File Field client side validation not working

cn flag

I am on Drupal 9.3.x

I just discovered that File Field in node entity form which is marked as required, not showing client side validation fail message. Rather it submitting the form and then showing the validation fail message.

This is causing issue for my modal form. I am loading the entity form's custom form mode into modal. The file field is marked as required, actually its a media field which is linked with a field field. So when user submitting the form, its not validating that, file is not uploaded and submitting the form, getting out of modal window and showing the validation fail message.

Searched in the net a lot, getting no clue. The following things tried:

  • Added an another test file field (not media field), its the same results
  • Added a custom managed file field using hook_form_alter, its the same results
  • Tried to submit the form through ajax, I see no form error reported for media field field

I am not sure if the as designed by Drupal or if there is any fix for it.

One more thing, field is added inside commerce product and field is showing inside inline entity form in simple mode.

Please help. :(

Score:0
in flag

I don't have a complete answer for you but I have run into the same issue. The root of the problem appears to be that Drupal doesn't support client side validation of a "managed_file". However if you switch your field type to "file" it should work. It appears this is an issue for many people but no true fix I've found yet. https://www.drupal.org/project/drupal/issues/2938441 https://www.drupal.org/project/drupal/issues/2301527

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.