Inputs
FormInput
Props
nameExtends HTML name input attribute.labelInput label. Defaults use the name prop if empty.typeExtends HTML type input attribute.valueInitial value.rulesList of rules for validation. See ValidationmaskMask pattern. See MasksuggestionsSuggestion object. See SuggestionsrequiredBoolean to set the input as required.disabledBoolean to disable the input.readonlyBoolean to set the input as read-only.placeholderPlaceholder text.
Exemple
<FormInput
name="fieldname"
label="Name"
:rules="['isNotEmpty']"
:suggestions="{ values: suggestions }"
/>FormSelect
Props
FormSelect extends FormInput props and adds the following options:
optionsKey-value object for select options.multipleBoolean for multiple select.emptyString with the empty label. Allows empty select
Example
<FormSelect
name="fieldname"
label="Name"
:options="{ 1: 'Foo', 2: 'Bar' }"
/>FormTextarea
Props
FormTextarea extends FormInput props and adds the following options:
rowsExtends the rows attribute from HTML textarea.
Example
<FormTextarea
name="fieldname"
label="Name"
rows="4"
/>FormRadio
Props
FormRadio extends FormInput props and adds the following options:
optionsKey-value object for select options.defaultDefault value.emptyBoolean to allow empty value
Example
<FormRadio
name="fieldname"
label="Name"
:options="{ 1: 'Foo', 2: 'Bar' }"
/>FormFile
Props
FormFile extends FormInput props and adds the following options:
acceptAccepts file types.
Exemple
<FormFile
name="fieldname"
label="File"
accept=".jpg"
/>FormSubmit
Props
validate-onlyOptional. Only trigger validation.
Exemple
<FormSubmit>
Submit
</FormSubmit>Suggestions
Suggestions can be applied to FormInput. The suggestion object follows this structure:
suggestions: {
type: 'list' | 'api' ,
fetchUrl?: string,
responsePath?: string,
responseKey?: string,
values?: string[] | { [key: string]: string } | string
},Suggestions have two possible types:
listWill search in values when the user types in the field and show suggestions.responseKeyis used for keying data if needed.
apiWill make an API call tofetchUrlwhen the input value length is greater than 3 and display results.responsePathis an option for routing data in response.
Example
<FormInput
name="fieldname"
label="Name"
:suggestions="{ type: 'api', fetchUrl: 'https://apiurl.test' }"
/>Masks
Nuxt-form uses Maska or masking input values. To use it, add a Maska pattern in the FormInput mask prop. mask prop. See all mask options in Maska documentation
Example
<FormInput
name="fieldname"
label="Name"
mask="###.####.####.##"
/>Custom Input
You can use FormInputContainer component for creating any custom input. It will initiate field data and add a validation system. Access and change data with form.data.state['fieldname']. You can add the FormSuggest and any other component inside.
Example
<script lang="ts" setup>
const form = inject('form')
</script>
<template>
<FormInputContainer name="fieldname" label="Name" :rules="['isNotEmpty']">
<input v-model="form.data.state['fieldname']" >
</FormInputContainer>
</template>