Drupal 7 – Increase the number of values per field

A long time ago, i have a post about hacking into the CCK module so we could have more options when settings the number of values per field in the field setting page.
Drupal – Increase Views Relationship Delta Limit

This is a dirty approach as mentioned by eosrei.

So in Drupal 7, we can do it by creating a custom module and alter the field_ui_field_edit_form. Let’s implement the following hook_form_FORM_ID_alter() in a custom module.

function <module>_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  // Increase the max cardinality to 20
  $range = drupal_map_assoc(range(1, 20));
  $new_options =  array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + $range;

  // Change the options
  $form['field']['cardinality']['#options'] = $new_options;
}

 

Go to the field setting page and now we can set the limit up to 20.
drupal7-increase-number-of-values-per-field
 

Done =)

Reference:

9 thoughts on “Drupal 7 – Increase the number of values per field”

  1. This appears to work for adding 11-20 to the fields. For whatever reason though it in not increasing the Delta limit beyond 10 in any of the relationships pages from within Views (even after I set the field for the relationship to a max number of 20). Is there something I’m missing? Thanks for your help!

    Like

      1. Ykyuen, Thank you so much for getting back to me. I apologize, I hadn’t realized you responded. I set the field = to 20 inside of a field collection. Then when I go to the relationship page in the view my option is any or (1-10) ideally what I need to do is be able to select delta 11 – 20 in the relationship selector in order to display the item in the 11th instance of the particular field in the field collection. I can send pictures if you think it will help. Thanks!

        Best,
        Shawn

        Like

  2. Any thoughts on this Ykyuen? I’ve been at it for a day or two now and haven’t come up with a solution. I’d really appreciate any help you can provide. If you need additional information from me please just let me know.

    Best,
    Shawn

    Like

    1. I have created a content type called Person and has a field collection called Item which is a field collection. The Item only has a multiple field called item name

      Person
        - Item (field collection)
          - item name (a multiple field which has 20 cardinality)
      

       

      So next i created a new view called People which select all the Person content. I added the Item field collection relationship.
      drupal7-cardinality-problem-1
       

      Then add the item name field and set the multiple field settings such that it will start from the 11th item name.
      drupal7-cardinality-problem-2
       

      Is that what u want?

      Like

  3. Hi,

    I have a select list field called “Number of installments” (1 to 20) on my custom content type.

    I also have a field collection item called “Installments” (Having date, note, amount fields in it)

    I want to dynamically add “Installments” based on the value of “Number of installments”.

    I want this to avoid clicking “add more” multiple times.

    Is it possible?

    Thank you very much.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.