You are here

function inline_entity_form_required_field in Inline Entity Form 7

IEF widget #element_validate callback: Required field validation.

1 string reference to 'inline_entity_form_required_field'
inline_entity_form_field_widget_form in ./inline_entity_form.module
Implements hook_field_widget_form().

File

./inline_entity_form.module, line 1470
Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (for example, order -> line items), where the child entities are never managed outside the…

Code

function inline_entity_form_required_field($element, &$form_state, $form) {
  $ief_id = $element['#ief_id'];
  $has_children = !empty($form_state['inline_entity_form'][$ief_id]['entities']);
  $form_open = !empty($form_state['inline_entity_form'][$ief_id]['form']);

  // If the add new / add existing form is open, its validation / submission
  // will do the job instead (either by preventing the parent form submission
  // or by adding a new referenced entity).
  if (!$has_children && !$form_open) {
    $instance = $form_state['inline_entity_form'][$ief_id]['instance'];
    form_error($element, t('!name field is required.', array(
      '!name' => $instance['label'],
    )));
  }
}