Form
Component Form
includes everything you need to start building forms without a hustle. It contains a submit button, auto self-validation in each input component which will link to the Form
they are contained, and finally it builds a submit object with all the names and values of its fields as properties.
Check console when clicking on submitForm button.
html
<Card>
<Form @submitForm="log">
<div class="row">
<div class="col-12 col-md-6 mb-xs-4">
<InputText
name="email"
label="E-mail"
placeholder="Enter your e-mail..."
icon="at"
inputType="email"
:validations="['not-empty', 'email']"
/>
</div>
<div class="col-12 col-md-6 mb-xs-4">
<InputPassword
name="password"
label="Password"
placeholder="Enter a secure password..."
:validations="['not-empty', { name: 'min-length', params: [8] }]"
/>
</div>
</div>
</Form>
</Card>
Props
validate
: Wether to auto self-validate theForm
or not. TypeBoolean
, defaulttrue
.
submitText
: Custom text for submit button. TypeString
, defaultnull
.
html
<Card>
<Form submitText="Submit" @submitForm="log">
<Checkbox name="conditions" label="I accept all the terms and conditions" required />
</Form>
</Card>
loading
: display submit button as loading and prevents clicking on it. TypeBoolean
, defaultfalse
.
html
<Card>
<Form loading submitText="Submitting" @submitForm="log">
<Checkbox name="conditions" label="I accept all the terms and conditions" required />
</Form>
</Card>
showSubmitButton
: show default submit button or you are going to implement your own submit button. TypeBoolean
, defaulttrue
.
html
<Card>
<Form :showSubmitButton="false" @submitForm="log">
<Checkbox name="conditions" label="I accept all the terms and conditions" required />
</Form>
</Card>
autoValidateOnStart
: Validate on start and disable submit button if form is not valid, or don't validate. TypeBoolean
, defaulttrue
.
html
<Card>
<Form :autoValidateOnStart="false" @submitForm="log">
<Checkbox name="conditions" label="I accept all the terms and conditions" required />
</Form>
</Card>
scrollOnFail
: scroll to the top of theForm
ifautoValidateOnStart
is disabled or you are using your own submit button, you click submit button, and validation fails. TypeBoolean
, defaultfalse
.
scrollToInvalidField
instead of scrolling to top of theForm
, scroll to the first component its validation failed. TypeBoolean
, defaultfalse
.
disableSubmitButton
: show submit button as disabled. TypeBoolean
, defaultfalse
.
resetOnSubmit
: to reset or not allForm
fields on submit. TypeBoolean
, defaultfalse
.
html
<Card>
<Form resetOnSubmit @submitForm="log">
<div class="row">
<div class="col-12 col-md-6 mb-xs-4">
<InputText
name="email"
label="E-mail"
placeholder="Enter your e-mail..."
icon="at"
inputType="email"
:validations="['not-empty', 'email']"
/>
</div>
<div class="col-12 col-md-6 mb-xs-4">
<InputPassword
name="password"
label="Password"
placeholder="Enter a secure password..."
:validations="['not-empty', { name: 'min-length', params: [8] }]"
/>
</div>
</div>
<div class="row">
<div class="col-12">
<Checkbox name="conditions" label="I accept all the terms and conditions" required />
</div>
</div>
</Form>
</Card>
skipUnmodifiedFields
: Skip fields that have not been modified when generating submit object. TypeBoolean
, defaultfalse
.
Emits
@submit
: native submit.
@submitForm
: custom submit.