2

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..

Amit
  • 342
  • 1
  • 13

3 Answers3

1

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']);
  }
}
Amit
  • 342
  • 1
  • 13
0


Seems like this is a perfect scenario for the Webform Add More module.
Unless you really need content types for this, would certainly recommend using the Webform. You may need to install the Webform module as a dependency for this which can allow you to quickly create forms you want for this purpose.

pal4life
  • 3,210
  • 5
  • 36
  • 57
0

Another solution is to use the Custom Add Another module https://www.drupal.org/project/custom_add_another to customise the button text and the benefit is that you can have different text for the button per field per bundle.