Skip to content

df-input Component ​

df-input is a single-line input of type text, email, password, URL or number.

Basic Usage ​

df-input with different input types:

Basic Text Input Examples
Field value:
Field validity:
Invalid
Validation errors:
  • Please enter a value

Number Input ​

With input-type="number", df-input renders Vuetify's v-number-input:

Number Input Example






Total: $10.99

Current Values:

Quantity: 1
Valid
Amount:
Price: 10.99
Valid

Features ​

  • Input types text, email, password, URL and number
  • v-number-input for the number type

Props ​

In addition to common props from InputBase, this component supports:

PropTypeDefaultDescription
inputType'text' | 'password' | 'email' | 'url' | 'number''text'Input type
minnumberundefinedMinimum value (for number inputs)
maxnumberundefinedMaximum value (for number inputs)
stepnumberundefinedStep value (for number inputs)
precisionnumber | nullnullDecimal precision (for number inputs)
anyDecimalSeparatorbooleanthe plugin's anyDecimalSeparator, else false. and , both act as the decimal separator (for number inputs). See Any decimal separator

The value (modelValue) is a string, or with inputType 'number' a number (null when empty).

Number Input Handling ​

When inputType is set to 'number', the component:

  1. Renders Vuetify's v-number-input with min, max, precision and step
  2. Marks the field touched on blur

v-number-input keeps the value within min and max: a typed value outside them shows Vuetify's error state and is not written while the user types, and is set to the nearest bound on blur. The field receives the value after that. min and max do not validate the field; a range the field refuses is a ValueInRange validator.

A bound value outside min and max, or with more decimals than precision, is kept until the user leaves the field. A value outside min and max is shown as it is, in Vuetify's error state; a value with more decimals is shown rounded to precision and in full while the field has focus. On blur v-number-input writes the value set to the nearest bound and rounded to precision.

While the field has focus, its text has no trailing decimal zeros beyond minFractionDigits (set through passthroughAttrs): v-number-input trims them on focus, and df-input trims them after a step with the arrow keys or the step controls (10.99 stepped by 0.01 shows 11). A digit typed after the step is appended (115). On blur the text shows precision decimals again (115.00).

Any decimal separator ​

v-number-input accepts one decimal separator: its decimalSeparator prop (set through passthroughAttrs), or the one of Vuetify's current locale (useLocale().decimalSeparator, , for sl, . for en). It refuses the other character. With anyDecimalSeparator, . and , both act as the decimal separator:

  • A typed . or , inserts the decimal separator. A number has one decimal separator: a . or , typed while the text already has one outside the selection is ignored.
  • Pasted text with the same separator more than once and no other one has only thousands separators, which are dropped: 1.000.000 and 1,000,000 give 1000000. Otherwise the last . or , is the decimal separator and the earlier ones are dropped as thousands separators: 1.234,56 and 1,234.56 give 1234.56, 1.000.000,5 gives 1000000.5. A single separator is the decimal separator: 1,234 gives 1.234.
  • The resulting text passes v-number-input's own checks: characters other than digits, - and the decimal separator are removed, and precision limits the decimals (with precision 0 the separator is dropped).

The option is off by default. anyDecimalSeparator in the plugin options turns it on for the whole application, and the prop sets it per field: :any-decimal-separator="false" turns it off for one field.

vue
<df-input :control="form.fields.amount" input-type="number" :precision="2" any-decimal-separator label="Amount" />

The Amount field in the number input example has the option on.

Events ​

This component emits the common events of InputBase.

Examples ​

Text Input ​

Length and format constraints are validators on the bound field, not props of the component: df-input accepts only the props listed above, and any other attribute is set on the wrapper element.

vue
<template>
  <df-input
    :control="form.fields.username"
    label="Username"
    hint="3 to 20 characters, letters, digits and underscores"
    :passthrough-attrs="{ autocomplete: 'username' }"
  />
</template>

<script setup>
import { Field, Group, Validators } from '@dynamicforms/vue-forms';
import { DfInput } from '@dynamicforms/vuetify-inputs';

const form = new Group({
  username: new Field({
    value: '',
    validators: [
      new Validators.MinLength(3),
      new Validators.MaxLength(20),
      new Validators.Pattern(/^[a-zA-Z0-9_]+$/, { code: 'app.username_chars', detail: 'Letters, digits and underscores only' }),
    ],
  }),
});
</script>

Native DOM attributes of the input element (autocomplete, inputmode, maxlength) are passed through passthroughAttrs, which is forwarded to the Vuetify component.

Number Input with DynamicForms ​

vue
<template>
  <df-input
    :control="form.fields.quantity"
    input-type="number"
    label="Quantity"
    hint="Enter the desired quantity"
    :min="1"
    :max="100"
    :step="1"
    :precision="0"
  />
</template>

<script setup>
import { Group, Field } from '@dynamicforms/vue-forms';
import { DfInput } from '@dynamicforms/vuetify-inputs';

const form = new Group({
  quantity: new Field({ value: 1 }),
});
</script>

Released under the MIT License.