Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By halloffame on
On unlimited value fields a button 'Add another item' is used to add an unlimited number of values for that field. Is there any way I could just enter a custom number of values when creating a node as opposed to clicking the Add another item button?
Sure we can define a fixed number of values under field settings but I'm facing a scenario where I need to define a custom number of a multi-value field upon node creation, then the fields will automatically load itself based on that custom number that I just defined, you know instead of me clicking the Add another item button several times.
Comments
As I understand you need to
As I understand you need to dynamically change the field numbers like in one form it may be 5 and in another it may be 10. Right?
Yes that is correct. To
Yes that is correct. To further explain it... Only one field is added everytime we click the 'Add another item' button. If we need 5 values for that field we need to click the Add another item button 4 times (1st one is already pre-loaded). I'm looking for a solution where the Add another item button generates a specific number of field based on an input from another field. Possible?
An ajax callback is triggered when we hit the Add another item button to load one field each time we click it. Can we somehow adjust this callback using hook_form_alter (or other hooks) and load an x number of fields defined on another field?
Did you find a solution for that?
Did you find a solution for that?
I am looking for a way to
I am looking for a way to open on initial form load a certain number of empty fields. Any idea how to do this?