Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/enum.js
"use strict"; | |||||
module.exports = { | module.exports = { | ||||
name: "enum", | name: "enum", | ||||
is_proper_value: async function(context, params, value) { | async is_proper_value(context, params, value) { | ||||
const allowed_values = | const allowed_values = | ||||
params.values instanceof Function | params.values instanceof Function | ||||
? await params.values() | ? await params.values() | ||||
: params.values; | : params.values; | ||||
if (allowed_values.indexOf(value) !== -1) { | if (allowed_values.includes(value)) { | ||||
return Promise.resolve(); | return Promise.resolve(); | ||||
} else { | |||||
return Promise.reject("Allowed values: " + allowed_values.join()); | |||||
} | } | ||||
return Promise.reject(`Allowed values: ${allowed_values.join()}`); | |||||
}, | }, | ||||
}; | }; |