Posted by becw on December 16, 2010 at 12:24am
9 followers
| Project: | Media |
| Version: | 7.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | Media Initiative, sprint |
Issue Summary
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.
Comments
#1
Here's the patch.
#2
This bug is still present in the latest 7.x-1.x-dev. I've re-rolled the patch so that it applies cleanly.
#3
This 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...
#4
When 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.)
#5
@bec: As always, you rock :)
Committed.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.
#7
The 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.
#8
#7 works for me
#9
The last submitted patch, 999594_7-media-element-required.patch, failed testing.
#10
Though #7 needs to be re-rolled against the correct directory.
#11
This patch won't work for a form element with the type set to 'media'.
$form['fid'] = array('#type' => 'media',
'#title' => t('Image'),
'#default_value' => array('fid' => '')),
'#required' => TRUE,
);
#12
daffie: The media field has been deprecated.
#13
#14
@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.
#15
per #7 and please patch against latest dev.
#16
I fixed the label part.
Previous commit for another issue accidentally fixed the other part.
marking as fixed.
#17
Automatically closed -- issue fixed for 2 weeks with no activity.
#18
Not 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.
#19
#20
can 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
#21
Done.
#22
awesome, thanks:)