Hello community!
I am trying to implement smart fields to edit fields stored in a object (as ForestAdmin only supports first level edit in the UI).
Here’s an abstract of my schema:
const criteriaSchema = mongoose.Schema({
type: [{
type: String,
enum: ['A1', 'A2', 'A3']
}],
jobType: [{
type: String,
enum: ['B1', 'B2', 'B3', 'B4']
}],
...
})
const schema = mongoose.Schema({
...,
criteria: criteriaSchema,
...,
})```
And here’s my forest config:
actions: [...],
fields: [{
field: 'Criteria Type',
type: ['Enum'],
enums: ['A1', 'A2', 'A3'],
get: property => {
if (property && property.criteria && property.criteria.type) return property.criteria.type
else return null
},
set: ((property, value) => {
if (!property.criteria) {
property.criteria = {};
}
property.criteria.type = value;
})
}, {
field: 'Criteria JobType',
type: ['Enum'],
enums: ['B1', 'B2', 'B3', 'B4'],
get: property => {
if (property && property.criteria && property.criteria.jobType) return property.criteria.jobType
else return null
},
set: ((property, value) => {
if (!property.criteria) {
property.criteria = {};
}
property.criteria.jobType = value;
})
}],
segments: [],
})
Expected behavior
When I edit a particular Smart Field, others Smart Fields should not change (it should only edit the field I’m a actually editing)
Actual behavior
- if I edit “Criteria Type”, “Criteria JobType” becomes empty
- if I edit “Criteria JobType”, “CriteriaType” becomes empty
- if I edit both, it works fine
Note that it only affects smart fields.
Am I missing something in the setter declaration?
Thanks in advance for your help!
Context
- forest-express-mongoose: 6.7.2
- express: ~4.17.1
- mongoose: ~5.8.2