Module Description
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.
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.
Module Link
Project Usage
6409
Security Covered
Covered By Security Advisory
Version Available
Production
Module Summary
This module aims to solve the UI oddity where users are asked to leave a field empty, set to 0, or set to -1 for an unlimited value, by providing a custom render element and field widget allowing the user to choose 'Unlimited' or a number value.
Data Name
unlimited_number