Hello, thank you for the module. I encountered problem similar to the one from New feature "This field is required for:" but with Drupal 7 version.

I fixed it by changing this code:

/**
 * Implements hook_field_widget_form_alter().
 */
function multiple_registration_field_widget_form_alter(&$element, &$form_state, $context) {
  $instance = isset($context['instance']) ? $context['instance'] : array();
  if (!empty($instance['settings']['user_additional_register_form'])) {

    // If nothing was selected.
    if (max($instance['settings']['user_additional_register_form']) === 0) {
      return;
    }
    $element['#access'] = multiple_registration_is_field_accessible($instance);
  }
}

to this:

/**
 * Implements hook_field_widget_form_alter().
 */
function multiple_registration_field_widget_form_alter(&$element, &$form_state, $context) {
  $instance = isset($context['instance']) ? $context['instance'] : array();
  if (!empty($instance['settings']['user_additional_register_form'])) {

    // If nothing was selected.
    if (max($instance['settings']['user_additional_register_form']) === 0) {
      return;
    }
    $element['#access'] = multiple_registration_is_field_accessible($instance);
    if(!$element['#access']){
      $element['value']['#required'] = FALSE;
    }
  }
}

If user should access the field from registration page value of #required is unchanged, but if the #access is FALSE and field is not available to the user, then #required is set to FALSE, so that user can submit registration form successfully.

Comments

miksha created an issue. See original summary.

ysamoylenko’s picture

Issue tags: +epam-contrib-2019.03
ysamoylenko’s picture

Issue tags: -epam-contrib-2019.03
karschsp’s picture

Here's a patch that incorporates @miksha's snippet from the original issue summary.

  • ysamoylenko committed 87000f5 on 7.x-1.x authored by karschsp
    Issue #3034827 by karschsp: Required field and "This field is needed for...
ysamoylenko’s picture

Status: Needs review » Fixed

Thank you for the report.
The patch was committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.