Skip to content
Permalink
Browse files

fix(validation): add validation for static, fix multiple choice (#228)

* fix(validation): add validation for static, fix multiple choice

Optional multiple choice fields have `null` as value.

* fix(style): use assert instead of console.error
  • Loading branch information...
czosel committed May 13, 2019
1 parent 41ba470 commit 7ab76a7f329f6904693ff71e6f4c3262332470b9
Showing with 23 additions and 3 deletions.
  1. +2 −0 addon/components/cf-field/input/table.js
  2. +21 −3 addon/lib/field.js
@@ -107,6 +107,8 @@ export default Component.extend(ComponentQueryManager, {

this.set("showModal", false);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
this.get("notification").danger(
this.get("intl").t("caluma.form.notification.table.add.error")
);
@@ -234,9 +234,15 @@ export default EmberObject.extend(Evented, {
* @method validate
*/
validate: task(function*() {
const specificValidation = this.get(`_validate${this.question.__typename}`);
assert(
"Missing validation function for " + this.question.__typename,
specificValidation
);

const validationFns = [
...(!this.question.hidden ? [this._validateRequired] : []),
this.get(`_validate${this.question.__typename}`)
specificValidation
];

const errors = (yield all(
@@ -351,7 +357,11 @@ export default EmberObject.extend(Evented, {
* @internal
*/
_validateMultipleChoiceQuestion() {
return this.getWithDefault("answer.value", []).map(value =>
const value = this.get("answer.value");
if (!value) {
return true;
}
return value.map(value =>
validate("inclusion", value, {
in: this.getWithDefault("question.multipleChoiceOptions.edges", []).map(
option => option.node.slug
@@ -385,7 +395,11 @@ export default EmberObject.extend(Evented, {
* @internal
*/
_validateDynamicMultipleChoiceQuestion() {
return this.getWithDefault("answer.value", []).map(value => {
const value = this.get("answer.value");
if (!value) {
return true;
}
return value.map(value => {
return validate("inclusion", value, {
in: this.getWithDefault(
"question.dynamicMultipleChoiceOptions.edges",
@@ -417,5 +431,9 @@ export default EmberObject.extend(Evented, {
return validate("date", this.get("answer.value"), {
allowBlank: true
});
},

_validateStaticQuestion() {
return true;
}
});

0 comments on commit 7ab76a7

Please sign in to comment.
You can’t perform that action at this time.