Skip to content

fixes #340 - "none" value set to null, formatValueToField checks fo… #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the schema.required was a good solution, because null can be a good & valid value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverting this change back to schema.required


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