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

bjaspan’s picture

Why 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.

yched’s picture

That would mean a 'required' error would be reported twice - once by FAPI, the other one by field validation ?

bjaspan’s picture

Hmmm. 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.

yched’s picture

Yes - 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'.

thedavidmeister’s picture

Version: 7.x-dev » 8.x-dev
Category: Task » Bug report
Issue summary: View changes

Bumping versions and setting as a bug, as per the OP.

swentel’s picture

Status: Active » Closed (duplicate)