Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I add a "Media file selector" field to a node and set it as a required field, and then visit the node create/edit form, there is no asterisk indicating the field is required, and submitting the form without a value in the field does not trigger a validation error.
Patch coming shortly.
Comment | File | Size | Author |
---|---|---|---|
#18 | 999594-18-media-element-required.patch | 422 bytes | azinck |
#7 | 999594_7-media-element-required.patch | 855 bytes | bmcmurray |
#2 | 999594_2-media-required_fields.patch | 1.68 KB | becw |
#1 | 999594_1-media-required_fields.patch | 1.63 KB | becw |
Comments
Comment #1
becw CreditAttribution: becw commentedHere's the patch.
Comment #2
becw CreditAttribution: becw commentedThis bug is still present in the latest 7.x-1.x-dev. I've re-rolled the patch so that it applies cleanly.
Comment #3
JacobSingh CreditAttribution: JacobSingh commentedThis seems like a no-brainer. I don't have time to test right now, but my understanding was that the required property would "just work" and doesn't need to be additionally specified. Is this not the case? If I look in system.module, I don't see it specified in most element_info arrays.
I'm a bit foggy on this area of the code...
Comment #4
becw CreditAttribution: becw commentedWhen you're providing your own element type, you have to deal with the #required property yourself: the 'media' FAPI element type gets built out within the media module, and it needs to add the property to its child input elements. (I think that #required isn't inherited by FAPI descendants.)
Comment #5
JacobSingh CreditAttribution: JacobSingh commented@bec: As always, you rock :)
Committed.
Comment #7
bmcmurray CreditAttribution: bmcmurray commentedThe default 'fid' of a media input is
'0'
, that is, zero as a string. This is causing the check in media_element_validate to never catch an empty submission on a required field.Additionally, $element['#title'] appears to be empty regardless of whether the form element has a label set or not, so I've modified the error thrown when a required field isn't found to use:
$form_state['field'][$field_name][$lang]['instance']['label']
Patch attached.
Comment #8
azinck CreditAttribution: azinck commented#7 works for me
Comment #10
azinck CreditAttribution: azinck commentedThough #7 needs to be re-rolled against the correct directory.
Comment #11
daffie CreditAttribution: daffie commentedThis patch won't work for a form element with the type set to 'media'.
Comment #12
azinck CreditAttribution: azinck commenteddaffie: The media field has been deprecated.
Comment #13
Dave ReidComment #14
daffie CreditAttribution: daffie commented@azinck: Thank you for the info. I have switched back to 7.x-1.x. I am following Media gallery to see how they will solve this problem.
Comment #15
dddave CreditAttribution: dddave commentedper #7 and please patch against latest dev.
Comment #16
ParisLiakos CreditAttribution: ParisLiakos commentedI fixed the label part.
Previous commit for another issue accidentally fixed the other part.
marking as fixed.
Comment #18
azinck CreditAttribution: azinck commentedNot fixed for me. In a multi-value form one of the values that comes through is the text of the "add another" button which is a string, not an array. The existing method of checking for empty fails when it hits this string.
Comment #19
azinck CreditAttribution: azinck commentedComment #20
ParisLiakos CreditAttribution: ParisLiakos commentedcan you please incorporate your patch in the issue here #1558830: media_element_validate() has hardcoded $form_state values reference and does not work with unlimited
Comment #21
azinck CreditAttribution: azinck commentedDone.
Comment #22
ParisLiakos CreditAttribution: ParisLiakos commentedawesome, thanks:)