Skip to content

Commit

Permalink
added an optional "unique" flag to "getFieldID" that appends lodash "…
Browse files Browse the repository at this point in the history
…uniqueId" to the ID when true. Fixes #468
  • Loading branch information
zoul0813 committed Dec 10, 2018
1 parent a484031 commit ab1daeb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/fields/abstractField.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get as objGet, forEach, isFunction, isString, isArray, debounce } from "lodash";
import { get as objGet, forEach, isFunction, isString, isArray, debounce, uniqueId } from "lodash";
import validators from "../utils/validators";
import { slugifyFormID } from "../utils/schema";

Expand Down Expand Up @@ -208,9 +208,9 @@ export default {
}
},

getFieldID(schema) {
getFieldID(schema, unique = false) {
const idPrefix = objGet(this.formOptions, "fieldIdPrefix", "");
return slugifyFormID(schema, idPrefix);
return slugifyFormID(schema, idPrefix) + (unique ? "-" + uniqueId() : "");
},

getFieldClasses() {
Expand Down
4 changes: 2 additions & 2 deletions src/fields/core/fieldChecklist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.listbox.form-control(v-if="schema.listBox", :disabled="disabled")
.list-row(v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
label
input(:id="getFieldID(schema)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
input(:id="getFieldID(schema, true)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
| {{ getItemName(item) }}

.combobox.form-control(v-if="!schema.listBox", :disabled="disabled")
Expand All @@ -14,7 +14,7 @@
.dropList
.list-row(v-if="comboExpanded", v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
label
input(:id="getFieldID(schema)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
input(:id="getFieldID(schema, true)", type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)", :name="getInputName(item)", v-attributes="'input'")
| {{ getItemName(item) }}
</template>

Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldRadios.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
.radio-list(:disabled="disabled", v-attributes="'wrapper'")
label(v-for="item in items", :class="{'is-checked': isItemChecked(item)}", v-attributes="'label'")
input(:id="getFieldID(schema)", type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="schema.fieldClasses", :required="schema.required", v-attributes="'input'")
input(:id="getFieldID(schema, true)", type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)", :class="schema.fieldClasses", :required="schema.required", v-attributes="'input'")
| {{ getItemName(item) }}

</template>
Expand Down

0 comments on commit ab1daeb

Please sign in to comment.