3.x is functionally identical to previous version, except it requires Drupal 11.4 and later. We are using a new major primarily as a method to excise sites who depend on this project because of a legacy RNG installation, not because they need it in the current day.
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.
Ask your assistant about Unlimited Number Field
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.