Commit 3d3a7e45 authored by Tobinsk's avatar Tobinsk
Browse files

Merge branch '30-validate-matchfield' into 'master'

Resolve "validate matchField"

Closes #30

See merge request !27
parents 60e425f4 37c18e63
Pipeline #6488 passed with stage
in 5 minutes and 47 seconds
......@@ -49,6 +49,16 @@
You need to configure at least one matching option.
</div>
</b-row>
<b-row v-show="!$v.single.parameters.maxLength" class="invalid-feedback-1">
<div class="col-12">
You can just configure 4 matching options. More is not possible.
</div>
</b-row>
<b-row v-show="!$v.single.parameters.uniqueField" class="invalid-feedback-1">
<div class="col-12">
Please select for each matching option a different field.
</div>
</b-row>
</b-form>
</FormContainer>
</transition>
......@@ -59,8 +69,25 @@
<script>
import MatchField from "@/components/MatchField";
import FormContainer from "@/components/FormContainer";
import {mapActions, mapGetters, mapMutations} from 'vuex';
import { required, minLength, between } from 'vuelidate/lib/validators'
import {mapActions, mapGetters} from 'vuex';
import { required, minLength, maxLength } from 'vuelidate/lib/validators';
/**
* Validator to check that each field is selected just once
* @param value
* @return {boolean}
*/
const uniqueField =
(value) => {
const fields = [];
return !value.some((p) => {
if(fields.some((f) => f === p.field)){
return true
}
fields.push(p.field);
return false;
})
}
export default {
name: "MatchForm",
components: {MatchField, FormContainer},
......@@ -83,6 +110,8 @@
parameters: {
required,
minLength: minLength(1),
maxLength: maxLength(4),
uniqueField,
$each: {
field: {
required,
......@@ -157,10 +186,15 @@
return $dirty ? !$error : null;
},
/**
* Check nested parameter
* @param index {number}
**/
validateParameter(index) {
const { $dirty, $error } = this.$v.single.parameters.$each.$iter[index];
return $dirty ? !$error : null;
},
/**
* Remove single search field
* @param index
......@@ -180,6 +214,7 @@
option2: '',
type: 'string',
});
// init validator for the field
this.$v.single.parameters.$each.$iter[this.single.parameters.length - 1].$touch()
},
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment