1

I would like to have integer field that ranges from 0 to lets say 100000 with "select list" widget. It doesn't have to have keys i just don't want to type 10000 numbers in field settings of "List integer" field. If I select integer field type it offers min and max but there is no option to have "select list" widget. Am I missing something obvious?

1
1

It may not be the best way to do this, but it might work for you... you can set up the field as a list and leave it empty, then use a PHP script to populate it, EXAMPLE being your field name:

for ($i=0; $i<100000; $i++) {
      // Get the field info
      $info = field_info_field('field_EXAMPLE');
      // Get a reference to the values
      $values = &$info['settings']['allowed_values'];
      // Manipulate the values in some way, e.g.
      $values[$i] =  $i;
      // Save the field
      field_update_field($info); 
}

Then you should be able to see the value listed under your field's values (under admin/structure/content/types/YOURAPGETYPE/fields). You can also use this in the future if you need to add more values, just remove/modify the for loop. I can't take credit for this code, I found it here on SE but just can't remember where.

2
  • clever. i was trying to avoid custom php as it seems such an obvious function to have.
    – sylwester
    Apr 16 '13 at 10:50
  • took 4min to create 500 options with that script. Works but very poor performance
    – sylwester
    Apr 16 '13 at 14:45
0

I went with creating these options in Excel with simple B1=A1+1 and then copy and paste that column - works well

0

Where can I put that code? Is it in hook_form_alter?

This is for to turn a text field into a drop down on view.

Can be seen here for the ages from and to:

age to and from drop down needed: can be seen at www.vuxi.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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