Issue #980144 by DuaelFr, yched, ACF, aerozeppelin, poedan, tim.plunkett, mgifford, swentel, SamH, asgorobets, dxvargas, sun, Everett Zufelt, alexpott: Issues with "required, multiple" fields in forms
parent
2d51757569
commit
ab6168bcd1
|
@ -213,14 +213,25 @@ function field_multiple_value_form($field, $instance, $langcode, $items, &$form,
|
||||||
'#language' => $langcode,
|
'#language' => $langcode,
|
||||||
'#field_parents' => $parents,
|
'#field_parents' => $parents,
|
||||||
'#columns' => array_keys($field['columns']),
|
'#columns' => array_keys($field['columns']),
|
||||||
// For multiple fields, title and description are handled by the wrapping table.
|
'#title' => $title,
|
||||||
'#title' => $multiple ? '' : $title,
|
'#description' => $description,
|
||||||
'#description' => $multiple ? '' : $description,
|
|
||||||
// Only the first widget should be required.
|
// Only the first widget should be required.
|
||||||
'#required' => $delta == 0 && $instance['required'],
|
'#required' => $delta == 0 && $instance['required'],
|
||||||
'#delta' => $delta,
|
'#delta' => $delta,
|
||||||
'#weight' => $delta,
|
'#weight' => $delta,
|
||||||
);
|
);
|
||||||
|
// For multiple fields, title and description are handled by the wrapping
|
||||||
|
// table.
|
||||||
|
if ($multiple) {
|
||||||
|
if ($delta == 0) {
|
||||||
|
$element['#title'] = $title;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$element['#title'] = t('!title (value @number)', array('@number' => $delta + 1, '!title' => $title));
|
||||||
|
}
|
||||||
|
$element['#title_display'] = 'invisible';
|
||||||
|
$element['#description'] = '';
|
||||||
|
}
|
||||||
if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $element)) {
|
if ($element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $element)) {
|
||||||
// Input field for the delta (drag-n-drop reordering).
|
// Input field for the delta (drag-n-drop reordering).
|
||||||
if ($multiple) {
|
if ($multiple) {
|
||||||
|
|
|
@ -1810,6 +1810,27 @@ class FieldFormTestCase extends FieldTestCase {
|
||||||
// Test with several multiple fields in a form
|
// Test with several multiple fields in a form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the position of the required label.
|
||||||
|
*/
|
||||||
|
public function testFieldFormUnlimitedRequired() {
|
||||||
|
$this->field = $this->field_unlimited;
|
||||||
|
$this->field_name = $this->field['field_name'];
|
||||||
|
$this->instance['field_name'] = $this->field_name;
|
||||||
|
$this->instance['required'] = TRUE;
|
||||||
|
field_create_field($this->field);
|
||||||
|
field_create_instance($this->instance);
|
||||||
|
|
||||||
|
// Display creation form -> 1 widget.
|
||||||
|
$this->drupalGet('test-entity/add/test-bundle');
|
||||||
|
$result = $this->xpath("//label[not(contains(@class, 'element-invisible')) and contains(text(), :label)]/span/text()", array(':label' => $this->instance['label']));
|
||||||
|
$this->assertEqual($result[0], '*', 'Required symbol added to field label.');
|
||||||
|
// Check that the label of the field input is visually hidden and contains
|
||||||
|
// the field title and an indication of the delta for a11y.
|
||||||
|
$result = $this->xpath("//label[contains(@class, 'element-invisible') and contains(text(), :label)]/span/text()", array(':label' => $this->instance['label']));
|
||||||
|
$this->assertEqual($result[0], '*', 'Required symbol and field label are visually hidden.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests widget handling of multiple required radios.
|
* Tests widget handling of multiple required radios.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue