0

I have used following code and it works fine i.e 3 items are displayed, but the issue in my code is add another item button remains inactive on click.

<?php

function two_form_alter(&$form, $form_state, $form_id) {


  if($form_id == 'product_culinary_node_form') {
    $field_language = $form['field_tabs']['#language'];
    $items_count = 3;

    $field_name = 'field_tabs';
    $form_theme = $form[$field_name][$field_language]['#theme'];

    // Remove delete and add more buttons
    // $form[$field_name][LANGUAGE_NONE][0]['remove_button']['#access'] = FALSE;
    $form[$field_name][$field_language]['add_more']['#access'] = TRUE;

    $items = &$form_state['field'][$field_name][$field_language];

    // Generate required number of fields collection
    if ($items_count > 1 && $items['items_count'] != $items_count) {
      $items['items_count'] = $items_count;

      // $items['field']['cardinality'] = $items_count;
      $wrapper = $form[$field_name][$field_language]['add_more']['#ajax']['wrapper'];
      $field_parents = $form[$field_name][$field_language]['#field_parents'];
      $language = $form[$field_name][$field_language]['#language'];
      $after_build = $form[$field_name][$field_language]['#after_build'];
      $form[$field_name][$field_language] = field_multiple_value_form($items['field'], $items['instance'], $field_language, array(), $form, $form_state);
      // Reset theme function, as field_multiple_value_form hijacks it
      $form[$field_name][$field_language]['#theme'] = $form_theme;
      $form[$field_name][$field_language]['#after_build'] = $after_build;
      $form[$field_name][$field_language]['#language'] = $language;
      $form[$field_name][$field_language]['#field_parents'] = $field_parents;
      $form[$field_name][$field_language]['add_more']['#ajax']['wrapper'] = $wrapper;
    }
  }
}
2
  • Check out this issue, You might find something useful.
    – Yogesh
    Commented Feb 3, 2017 at 4:34
  • Yogesh, I have gone through almost all the patches and comments of the issue you have linked above and related posts. Nothing has worked till now.
    – neha
    Commented Feb 3, 2017 at 10:24

1 Answer 1

0

1 solution to this is https://www.drupal.org/node/1337804#comment-6326678. I will post another solution if found without form rebuild.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.