Skip to content

Commit 5b42807

Browse files
committed
fixes #340 - "none" value set to null, formatValueToField checks for isNil(value) and returns null, none options are always disabled
* updated tests to reflect "none is always disabled", could possibly be a selectOptions to allow users to select the "none" option to clear a previously selected value? * added formatValueToField and return `null` when `isNil(value)`
1 parent 268631a commit 5b42807

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

dist/vfg-core.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vfg.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fields/core/fieldSelect.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)", :class="schema.fieldClasses")
3-
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
3+
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="true", :value="null") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
44

55
template(v-for="item in items")
66
optgroup(v-if="item.group", :label="getGroupName(item)")
@@ -10,7 +10,7 @@
1010
</template>
1111

1212
<script>
13-
import {isObject, find} from "lodash";
13+
import {isObject, isNil, find} from "lodash";
1414
import abstractField from "../abstractField";
1515
1616
export default {
@@ -27,10 +27,16 @@
2727
return this.groupValues(values.apply(this, [this.model, this.schema]));
2828
} else
2929
return this.groupValues(values);
30-
}
30+
},
3131
},
3232
3333
methods: {
34+
formatValueToField(value) {
35+
if(isNil(value)) {
36+
return null;
37+
}
38+
return value;
39+
},
3440
3541
groupValues(values){
3642
let array = [];
@@ -123,7 +129,7 @@
123129
} else {
124130
return item;
125131
}
126-
}
132+
},
127133
}
128134
};
129135
</script>

test/unit/specs/fields/fieldSelect.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ describe("fieldSelect.vue", function () {
5656

5757
it("should contain a <non selected> element", () => {
5858
let options = input.querySelectorAll("option");
59-
expect(options[0].disabled).to.be.false;
59+
// "none selected" options are always disabled
60+
expect(options[0].disabled).to.be.true;
6061
expect(options[0].textContent).to.be.equal("<Nothing selected>");
6162
});
6263

0 commit comments

Comments
 (0)