Problem/Motivation
Field API can support "native" required fields but it is not used, instead we rely on the FAPI layer and #required to stop fields being submitted without data.
Proposed resolution
Stop relying on #required and use field_default_validate(). There is an aesthetic problem in that we still need the required "*" to appear in the UI that might require some kind of hack.
Remaining tasks
Figure out how to keep the UI the same.
User interface changes
None.
API changes
Required fields will be enforced on the Field API level instead of in the FAPI.
Original report by @yched
Since #369964: Refactor field validation and error reporting, field API is supposed to support validation on programmatic save.
The 'required' status escapes this, because it is handled through FAPI #required property. We need to move it into field_default_validate() instead.
Relying on FAPI also means we have the following bug (also in D6) :
empty the first row, fill a value in the second row, drag the first row below the second row, submit: validation error, because the #required is hardcoded on the first element ('required' means 'must have at least one value, so we only flag the first element as required)
Problem : we'll still want the 'required' theming on the field label.
Comments
Comment #1
bjaspan CreditAttribution: bjaspan commentedWhy is there a problem with 'required' themeing on the field label? We can still set the form elements as #required => TRUE, and also verify that data is present during field validation.
Comment #2
yched CreditAttribution: yched commentedThat would mean a 'required' error would be reported twice - once by FAPI, the other one by field validation ?
Comment #3
bjaspan CreditAttribution: bjaspan commentedHmmm. So if FAPI validation fails, field validation is still performed? I guess I thought that field validation on form submit would only run if FAPI validation passed.
Comment #4
yched CreditAttribution: yched commentedYes - well, technically field_attach_form_validate() is part of FAPI validation (it will generally be called during the _validate handler for the form).
And FAPI performs all validations, both element-level and form-level, so that you get all errors at once, and not 'you have these errors' / I fix the errors / 'cool, you have these other errors'.
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedBumping versions and setting as a bug, as per the OP.
Comment #6
swentel CreditAttribution: swentel commented#2095195: Remove deprecated field_attach_form_*() fixed most of it, leaving the last bit to #2002180: Entity forms skip validation of fields that are edited without widgets to fix that completely.