Number field
The number field is a fundamental field that stores a numeric value.
Examples
Here's an example of using the number field in a block:
# blocks/Product.vue
<template>
<div>
<span>Price: {{ price }} USD</span>
...
</div>
</template>
<script lang="ts" setup>
import { numberField } from '#pruvious'
defineProps({
price: numberField({
required: true,
decimals: 2,
min: 0,
suffix: 'USD',
}),
})
</script>
Here is another example of how to use it in a collection definition:
# collections/products.ts
import { defineCollection } from '#pruvious'
export default defineCollection({
name: 'products',
mode: 'multi',
fields: {
price: {
type: 'number',
options: {
required: true,
decimals: 2,
min: 0,
suffix: 'USD',
},
},
// ...
},
})
Options
You can specify the following options in the number field:
Option | Description |
---|---|
| Specifies the maximum number of allowed decimal places for the number. Set to |
| The default field value. By default, this is set to |
| A brief descriptive text displayed in code comments and in a tooltip at the upper right corner of the field. |
| The field label displayed in the UI. By default, it is automatically generated based on the property name assigned to the field. For example, numberOfGuests becomes Number of guests. |
| The maximum allowed number. |
| The minimum allowed number. |
| A string that specifies the |
| Text that appears in the input element when it has no value set. |
| A short text to be prepended before the input element. |
| Specifies whether the field input is mandatory. The requirement check allows the value |
| The |
| A short text to be appended after the input element. |
Last updated on January 8, 2024 at 19:36