mirror of
https://github.com/frappe/books.git
synced 2024-12-25 20:11:15 +00:00
fix: validate select for array of objects
This commit is contained in:
parent
1603346b20
commit
a53cc9f119
@ -255,11 +255,17 @@ module.exports = class BaseMeta extends BaseDocument {
|
|||||||
let options = field.options;
|
let options = field.options;
|
||||||
if (!options) return;
|
if (!options) return;
|
||||||
|
|
||||||
|
let validValues = options;
|
||||||
|
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
// values given as string
|
// values given as string
|
||||||
options = field.options.split('\n');
|
validValues = options.split('\n');
|
||||||
}
|
}
|
||||||
if (!options.includes(value)) {
|
if (typeof options[0] === 'object') {
|
||||||
|
// options as array of {label, value} pairs
|
||||||
|
validValues = options.map(o => o.value);
|
||||||
|
}
|
||||||
|
if (!validValues.includes(value)) {
|
||||||
throw new frappe.errors.ValueError(
|
throw new frappe.errors.ValueError(
|
||||||
`${value} must be one of ${options.join(', ')}`
|
`${value} must be one of ${options.join(', ')}`
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user