Skip to content

Commit dc6e74a

Browse files
author
Lionel Bijaoui
committed
Better groups
1 parent 4813d3c commit dc6e74a

24 files changed

+378
-307
lines changed

src/fields/abstractField.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { get as objGet, forEach, isFunction, isString, isArray, debounce, isNil } from "lodash";
1+
import { get as objGet, forEach, isFunction, isString, isArray, debounce, isNil, uniqueId } from "lodash";
22
import validators from "../utils/validators";
3-
import { slugifyFormID } from "../utils/schema";
43

54
const convertValidator = (validator) => {
65
if (isString(validator)) {
@@ -37,11 +36,16 @@ export default {
3736
},
3837
eventBus: {
3938
type: Object
39+
},
40+
fieldID: {
41+
type: String
4042
}
4143
},
4244

4345
data() {
46+
const fieldUID = uniqueId(this.fieldID + "_");
4447
return {
48+
fieldUID,
4549
errors: [],
4650
debouncedValidateFunc: null,
4751
debouncedFormatFunction: null
@@ -109,19 +113,21 @@ export default {
109113

110114
watch: {
111115
errors: {
112-
handler: function(errors) {
116+
handler(errors) {
113117
this.$emit("errors-updated", errors);
114118
}
115119
}
116120
},
117121

118122
methods: {
119123
getValueFromOption(field, option, defaultValue) {
120-
if (typeof this.$parent.getValueFromOption === "function") {
124+
if (isFunction(this.$parent.getValueFromOption)) {
121125
return this.$parent.getValueFromOption(field, option, defaultValue);
122126
} else {
123127
// Environnement de test ?
124-
if (isNil(field[option])) return defaultValue;
128+
if (isNil(field[option])) {
129+
return defaultValue;
130+
}
125131

126132
return field[option];
127133
}
@@ -142,12 +148,12 @@ export default {
142148
if (!isArray(this.schema.validator)) {
143149
validators.push(convertValidator(this.schema.validator).bind(this));
144150
} else {
145-
forEach(this.schema.validator, (validator) => {
151+
this.schema.validator.forEach((validator) => {
146152
validators.push(convertValidator(validator).bind(this));
147153
});
148154
}
149155

150-
forEach(validators, (validator) => {
156+
validators.forEach((validator) => {
151157
if (validateAsync) {
152158
results.push(validator(this.value, this.schema, this.model));
153159
} else {
@@ -167,7 +173,7 @@ export default {
167173

168174
let handleErrors = (errors) => {
169175
let fieldErrors = [];
170-
forEach(errors, (err) => {
176+
errors.forEach((err) => {
171177
if (isArray(err) && err.length > 0) {
172178
fieldErrors = fieldErrors.concat(err);
173179
} else if (isString(err)) {
@@ -182,7 +188,7 @@ export default {
182188

183189
this.errors = fieldErrors;
184190

185-
this.eventBus.$emit("field-validated", isValid, fieldErrors, this._uid);
191+
this.eventBus.$emit("field-validated", isValid, fieldErrors, this.fieldUID);
186192
return fieldErrors;
187193
};
188194

@@ -265,11 +271,6 @@ export default {
265271
}
266272
},
267273

268-
getFieldID(schema) {
269-
const idPrefix = objGet(this.formOptions, "fieldIdPrefix", "");
270-
return slugifyFormID(schema, idPrefix);
271-
},
272-
273274
formatValueToField(value) {
274275
return value;
275276
},

src/fields/core/fieldCheckbox.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input(:id="getFieldID(schema)", type="checkbox", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :name="inputName", :class="fieldClasses", v-attributes="'input'")
2+
input(:id="fieldID", type="checkbox", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :name="inputName", :class="fieldClasses", v-attributes="'input'")
33
</template>
44

55
<script>

src/fields/core/fieldChecklist.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.listbox.form-control(v-if="useListBox", :disabled="disabled")
44
.list-row(v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
55
label
6-
input(:id="getFieldID(schema)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
6+
input(:id="fieldID", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
77
| {{ getItemName(item) }}
88

99
.combobox.form-control(v-if="!useListBox", :disabled="disabled")
@@ -14,7 +14,7 @@
1414
.dropList
1515
.list-row(v-if="comboExpanded", v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
1616
label
17-
input(:id="getFieldID(schema)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
17+
input(:id="fieldID", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
1818
| {{ getItemName(item) }}
1919
</template>
2020

src/fields/core/fieldInput.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
.wrapper(v-attributes="'wrapper'")
33
input.form-control(
4-
:id="getFieldID(schema)",
4+
:id="fieldID",
55
:type="inputType",
66
:value="value",
77
@input="onInput",

src/fields/core/fieldLabel.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
span(:id="getFieldID(schema)", :class="fieldClasses", v-attributes="'label'") {{ value }}
2+
span(:id="fieldID", :class="fieldClasses", v-attributes="'label'") {{ value }}
33
</template>
44

55
<script>

src/fields/core/fieldRadios.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
.radio-list(:disabled="disabled", v-attributes="'wrapper'")
33
label(v-for="item in items", :class="{'is-checked': isItemChecked(item)}", v-attributes="'label'")
4-
input(:id="getFieldID(schema)", type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="fieldClasses", v-attributes="'input'")
4+
input(:id="fieldID", type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="fieldClasses", v-attributes="'input'")
55
| {{ getItemName(item) }}
66

77
</template>

src/fields/core/fieldSelect.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
select.form-control(v-model="value", :disabled="disabled", :name="inputName", :id="getFieldID(schema)", :class="fieldClasses", v-attributes="'input'")
2+
select.form-control(v-model="value", :disabled="disabled", :name="inputName", :id="fieldID", :class="fieldClasses", v-attributes="'input'")
33
option(v-if="!fieldOptions.hideNoneSelectedText", :disabled="schema.required", :value="null") {{ fieldOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
44

55
template(v-for="item in items")

src/fields/core/fieldSubmit.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input(:id="getFieldID(schema)", type="submit", :value="fieldOptions.buttonText", @click="onClick", :name="inputName", :disabled="disabled", :class="fieldClasses", v-attributes="'input'")
2+
input(:id="fieldID", type="submit", :value="fieldOptions.buttonText", @click="onClick", :name="inputName", :disabled="disabled", :class="fieldClasses", v-attributes="'input'")
33
</template>
44

55
<script>

src/fields/core/fieldTextArea.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
textarea.form-control(
33
v-model="value",
4-
:id="getFieldID(schema)",
4+
:id="fieldID",
55
:class="fieldClasses",
66
:disabled="disabled",
77
:maxlength="fieldOptions.max",

src/fields/core/fieldUpload.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
.wrapper(v-attributes="'wrapper'")
33
input.form-control(
4-
:id="getFieldID(schema)",
4+
:id="fieldID",
55
type="file",
66
:name="inputName",
77
@change="onChange",

src/fields/optional/fieldCleave.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input.form-control(type="text", :value="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="getFieldID(schema)")
2+
input.form-control(type="text", :value="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
33
</template>
44

55
<script>

src/fields/optional/fieldDateTimePicker.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
.input-group.date
3-
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="getFieldID(schema)")
3+
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
44
span.input-group-addon
55
span.glyphicon.glyphicon-calendar
66
</template>

src/fields/optional/fieldGoogleAddress.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", debounce="500", @focus="geolocate()", :id="getFieldID(schema)")
2+
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", debounce="500", @focus="geolocate()", :id="fieldID")
33
</template>
44

55
<script>

src/fields/optional/fieldMasked.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="getFieldID(schema)")
2+
input.form-control(type="text", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
33
</template>
44

55
<script>

src/fields/optional/fieldSpectrum.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template lang="pug">
2-
input(type="text", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="getFieldID(schema)")
2+
input(type="text", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :placeholder="placeholder", :readonly="readonly", :name="inputName", :id="fieldID")
33
</template>
44

55
<script>

src/fields/optional/fieldSwitch.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
label
3-
input(type="checkbox", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :name="inputName", :id="getFieldID(schema)")
4-
span.label(:data-on="fieldOptions.textOn || 'On'", :data-off="fieldOptions.textOff || 'Off'", :for="getFieldID(schema)")
3+
input(type="checkbox", v-model="value", :autocomplete="fieldOptions.autocomplete", :disabled="disabled", :name="inputName", :id="fieldID")
4+
span.label(:data-on="fieldOptions.textOn || 'On'", :data-off="fieldOptions.textOff || 'Off'", :for="fieldID")
55
span.handle
66
</template>
77

0 commit comments

Comments
 (0)