1
0
mirror of synced 2024-11-25 14:56:03 +03:00

docs: Updated story of address list - added possibility to remove items from list; removed outdated story

This commit is contained in:
Zaytsev Kirill 2020-11-11 19:46:31 +03:00 committed by Zaytsev Kirill
parent 46423dc8c6
commit 9c758e9fbf
3 changed files with 25 additions and 111 deletions

View File

@ -42,7 +42,7 @@
v-slot="{ context }" v-slot="{ context }"
class="col col-auto px-2 mb-3" class="col col-auto px-2 mb-3"
name="building" name="building"
validation="^required|number" validation="^required|alphanumeric"
> >
<label for="address-building">Building <span class="text-danger">*</span></label> <label for="address-building">Building <span class="text-danger">*</span></label>
<input <input
@ -61,6 +61,16 @@
{{ error }} {{ error }}
</div> </div>
</FormularioInput> </FormularioInput>
<div class="remove-btn-wrapper">
<button
class="btn btn-danger"
type="button"
@click="removeAddress(addressIndex)"
>
Remove
</button>
</div>
</FormularioGrouping> </FormularioGrouping>
</FormularioGrouping> </FormularioGrouping>
@ -91,14 +101,18 @@ export default {
data: () => ({ data: () => ({
values: { values: {
addressList: [], addressList: [{
street: 'Baker Street',
building: '221b',
}],
}, },
}), }),
created () { created () {
this.$formulario.extend({ this.$formulario.extend({
validationMessages: { validationMessages: {
number: () => 'Value is not a number', alphanumeric: () => 'Value must be alphanumeric',
number: () => 'Value must be a number',
required: () => 'Value is required', required: () => 'Value is required',
}, },
}) })
@ -111,6 +125,10 @@ export default {
building: '', building: '',
}) })
}, },
removeAddress (index) {
this.values.addressList.splice(index, 1)
},
}, },
} }
</script> </script>
@ -119,4 +137,8 @@ export default {
.field { .field {
max-width: 250px; max-width: 250px;
} }
.remove-btn-wrapper {
padding-top: 32px;
}
</style> </style>

View File

@ -1,106 +0,0 @@
<template>
<div>
<div
v-for="(item, groupIndex) in groups"
:key="groupIndex"
>
<FormularioGrouping :name="`groups[${groupIndex}]`">
<FormularioInput
v-slot="{ context }"
class="mb-3"
name="text"
validation="number|required"
validation-behavior="live"
>
<label for="text-field">Text field (number|required)</label>
<input
id="text-field"
v-model="context.model"
type="text"
class="form-control"
style="max-width: 250px;"
>
<div
v-for="(error, index) in context.allErrors"
:key="index"
class="text-danger"
>
{{ error }}
</div>
</FormularioInput>
<FormularioInput
v-slot="{ context }"
:validation-messages="{ in: 'The value was different than expected' }"
class="mb-3"
name="abcdef-field"
validation="in:abcdef"
validation-behavior="live"
>
<label for="abcdef-field">Text field (in:abcdef)</label>
<input
id="abcdef-field"
v-model="context.model"
type="text"
class="form-control"
style="max-width: 250px;"
>
<div
v-for="(error, index) in context.allErrors"
:key="index"
class="text-danger"
>
{{ error }}
</div>
</FormularioInput>
</FormularioGrouping>
<button @click="onRemoveGroup(groupIndex)">
Remove Group
</button>
</div>
<button @click="onAddGroup">
Add Group
</button>
</div>
</template>
<script>
import FormularioGrouping from '@/FormularioGrouping'
import FormularioInput from '@/FormularioInput'
export default {
name: 'FormularioGroupingGroupTale',
components: {
FormularioGrouping,
FormularioInput,
},
model: {
prop: 'groups',
event: 'change'
},
props: {
groups: {
type: Array,
required: true,
},
},
methods: {
onAddGroup () {
this.$emit('change', this.groups.concat([{}]))
},
onRemoveGroup (removedIndex) {
this.$emit('change', this.groups.filter((item, index) => {
return index !== removedIndex
}))
}
}
}
</script>

View File

@ -6,7 +6,6 @@ import Vue from 'vue'
import VueFormulario from '../../dist/formulario.esm' import VueFormulario from '../../dist/formulario.esm'
import ExampleAddressList from './ExampleAddressList.tale' import ExampleAddressList from './ExampleAddressList.tale'
import FormularioGrouping from './FormularioGrouping.tale'
Vue.mixin({ Vue.mixin({
methods: { methods: {
@ -22,4 +21,3 @@ Vue.use(VueFormulario)
storiesOf('Examples', module) storiesOf('Examples', module)
.add('Address list', () => ExampleAddressList) .add('Address list', () => ExampleAddressList)
.add('FormularioGrouping', () => FormularioGrouping)