Search code examples
drupaldrupal-7drupal-modulesdrupal-field-collection

"Add more item button" to limited number of values


I have a scenario where in team leader enter his team members with their name and email id. I want to restrict team size to maximum of 10 team members. I am thinking of using Field Collection module to capture name and email values of team members. What I found is, this module provides "Add more item" button only if I select "Unlimited" in "Number of values" field for this collection. If I select "Number of values" to 10 it show 10 times "Name" and "Email". What I want is, it should show 1 set of "Name" and "Email" field, next to it should be "Add more" button which will show next "Name" and "Email" field set and so on till the count reaches 10(in my case).

Can any one help me with this or suggest me with some other module. Thank you in advance..


Solution

  • Found solution to my question. Select "Unlimited" in "Number of values" field for field collection and written below code in hook_form_alter. It shows "Add more" 10 times.

    if($form_id == 'form_id') {
      if (isset($form['field_collection_name']['und']['#max_delta']) && $form['field_collection_name']['und']['#max_delta'] >= 10) {
        unset($form['field_collection_name']['und']['add_more']);
      }
    }