Skip to content

Commit

Permalink
fixes #340 - "none" value set to null, formatValueToField checks fo…
Browse files Browse the repository at this point in the history
…r `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)`
  • Loading branch information
zoul0813 committed Dec 13, 2017
1 parent 268631a commit 5b42807
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions dist/vfg-core.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/vfg.js

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)", :class="schema.fieldClasses")
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="true", :value="null") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}

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

<script>
import {isObject, find} from "lodash";
import {isObject, isNil, find} from "lodash";
import abstractField from "../abstractField";
export default {
Expand All @@ -27,10 +27,16 @@
return this.groupValues(values.apply(this, [this.model, this.schema]));
} else
return this.groupValues(values);
}
},
},
methods: {
formatValueToField(value) {
if(isNil(value)) {
return null;
}
return value;
},
groupValues(values){
let array = [];
Expand Down Expand Up @@ -123,7 +129,7 @@
} else {
return item;
}
}
},
}
};
</script>
Expand Down
3 changes: 2 additions & 1 deletion test/unit/specs/fields/fieldSelect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ describe("fieldSelect.vue", function () {

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

Expand Down

0 comments on commit 5b42807

Please sign in to comment.