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.
Elasticsearch Mapping: double
YAML Definition
- name: quantity
type: number
display_name: "Quantity"
guidance: "Enter the number of items."
required: true
default_value: 1
readonly: false
hidden: false
validation: ""
validation_message: ""
precision: 0
format: ""
symbol: ""
formula: ""
sequence: false
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:false
. -
readonly (boolean): Optional.
Iftrue
, the field is read-only and cannot be edited by the user. Default:false
. -
hidden (boolean): Optional.
Iftrue
, the field is hidden from the user interface. Default:false
. -
default_value (number): Optional.
The default number displayed when the form is first loaded. -
validation (string): Optional.
Validation rules for the number field, such as minimum or maximum values. -
validation_message (string): Optional.
Custom validation error message to display when validation fails. -
precision (number): Optional.
Specifies the number of decimal places allowed. If not specified, any number of decimal places is accepted. -
format (string): Optional.
Number format specification. -
symbol (string): Optional.
Currency symbol or prefix for the field. -
formula (string): Optional.
Formula for calculated fields that derive their value from other fields. -
sequence (boolean): Optional.
Iftrue
, the field auto-increments. Default:false
.
Examples
Basic Number Field:
- name: quantity
type: number
display_name: "Quantity"
guidance: "Enter the number of items."
required: true
default_value: 1
Currency Field with Precision:
- name: unit_price
type: number
display_name: "Unit Price"
guidance: "Enter the price per unit."
required: true
precision: 2
symbol: "$"
validation: "min:0.01"
default_value: 0.00
Auto-incrementing Sequence Field:
- name: policy_holder_ref
type: number
sequence: true
display_name: "Policy Holder Reference"
readonly: true
Calculated Field:
- name: total_amount
type: number
display_name: "Total Amount"
formula: "quantity * unit_price"
readonly: true
precision: 2
symbol: "$"
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
- Currency and Symbols:
- Use the
symbol
attribute to display currency symbols or other prefixes. - Common symbols include
$
,€
,£
,%
, etc.
- Use the
- Sequences:
- Set
sequence: true
for auto-incrementing fields like reference numbers or IDs. - Sequence fields are typically read-only as they are system-generated.
- Set
- Formulas:
- Use
formula
for calculated fields that derive their value from other fields. - Formula fields are typically read-only as they are automatically calculated.
- Common formula operators include
+
,-
,*
,/
, and field references.
- Use
- 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.
- Currency: Prices, amounts, or financial calculations.
- Percentages: Ratios, completion rates, or statistical values.
- 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.