Number Field Type
Description:
The number
field type is used to capture numerical input from users. It supports both integer and decimal values, making it suitable for quantities, measurements, identifiers, and any data that requires numeric input. This field ensures that the data collected is numerical and can be used in calculations or data analysis within your application.
YAML Definition
- name: quantity
type: number
display_name: "Quantity"
guidance: "Enter the number of items."
required: true
default_value: 1
Attributes
-
name (string): Required.
The unique identifier for the field. -
type (string): Required.
Must be set tonumber
for number fields. -
display_name (string): Optional.
The label displayed in the user interface. If not provided, a formatted version ofname
is used. -
guidance (string): Optional.
Help text or instructions for the field, assisting users in understanding what data to enter. -
required (boolean): Optional.
Iftrue
, the field must be filled before submission. -
default_value (number): Optional.
The default number displayed when the form is first loaded. -
readonly (boolean): Optional.
Iftrue
, the field is read-only and cannot be edited by the user. -
hidden (boolean): Optional.
Iftrue
, the field is hidden from the user interface. -
precision (number): Optional.
Specifies the number of decimal places allowed. If not specified, any number of decimal places is accepted. -
validation (string): Optional.
Validation rules for the number field, such as minimum or maximum values.
Example
- name: unit_price
type: number
display_name: "Unit Price"
guidance: "Enter the price per unit."
required: true
precision: 2
validation: "min:0.01"
default_value: 0.00
In this example:
- unit_price: Captures the price of a single unit of a product.
- precision: Limits the input to two decimal places.
- validation: Ensures that the entered price is at least 0.01.
Usage Notes
-
User Input:
- The field accepts numeric input, including integers and decimals.
- If
precision
is specified, the input is limited to the defined number of decimal places.
-
Validation:
- Use the
validation
attribute to enforce rules such as minimum and maximum values. - Common validation formats include:
"min:0"
: Value must be greater than or equal to 0."max:100"
: Value must be less than or equal to 100."range:1-10"
: Value must be between 1 and 10.
- Use the
-
Default Values:
- Setting a
default_value
provides an initial value when the form loads, which can be edited by the user.
- Setting a
-
Readonly Fields:
- Use
readonly
to display calculated values or identifiers that should not be modified by the user.
- Use
-
Precision:
- For fields that require a specific number of decimal places (e.g., measurements, currency amounts), set the
precision
attribute accordingly. - If
precision
is not specified, the field accepts numbers with any number of decimal places.
- For fields that require a specific number of decimal places (e.g., measurements, currency amounts), set the
-
Guidance and Labels:
- Provide clear
display_name
andguidance
to help users understand what is expected.
- Provide clear
-
Use Cases:
- Quantities: Number of items, quantities in orders, or inventory counts.
- Measurements: Length, weight, volume, or any physical measurements.
- Identifiers: Numeric codes, serial numbers, or IDs that are numerical.
- Scores or Ratings: Numerical ratings or scores in surveys or assessments.
-
Internationalization:
- Be mindful of number formats in different locales, especially regarding decimal separators (e.g., periods vs. commas).
- Ensure that the input validation accepts the correct decimal separator based on the user’s locale.
By incorporating the number
field type into your schema, you ensure accurate and consistent capture of numerical data, which is essential for calculations, reporting, and data analysis within your application.