Adds a custom render element and field widget allowing the user to choose "Unlimited" or a number value.
The unlimited_number element renders a radios form element with an inline number field. Custom prefix and suffixes can be applied to the number field. The radio labels can also be customized.
This field eliminates the UI oddity where form descriptions will often request the user to leave a field empty, set to 0, or set to -1, where an unlimited value takes effect.
|
|
Support requests are taken on Drupal Answers with the fields tag. Ask a question! |
Discontinued Github project.
Usage
Form Element
// Define an unlimited_number form field.
// Only the #type key is required.
$form['my_field'] = [
'#type' => 'unlimited_number',
// Optional properties:
'#title' => $this->t('My field'),
'#description' => $this->t('Choose an option.'),
'#default_value' => 1, // an integer, or the string 'unlimited'.
'#required' => TRUE,
'#options' => [
// Customize the labels on the radios element.
'unlimited' => $this->t('No limit'),
'limited' => $this->t('Fixed value'),
],
// The following are applied to the number field.
'#min' => 1,
'#max' => 128,
'#step' => 1,
'#field_suffix' => 'units',
'#field_prefix' => NULL,
];
Field Widget
The field widget can be applied to any existing number field.
- Go to the Manage fields page for an entity type.
- Add a Number (integer) field if one does not yet exist.
- Go to Manage form display page.
- Locate the Widget select element located adjacent to your number field. Change the existing value to Unlimited or Number. Save the form.
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Administration tools, Developer tools, Site structure
7,861 sites report using this module
- Created by dpi on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.


