meteor-autoform
meteor-autoform copied to clipboard
Array of objects set last object fields to null when remove unordered element
Hello Guys, I have an array of objects 'schema' which all fields are 'options', client has to select emp_id based on that bus, dpt, are automatically filter their values, the problem is when i remove unordered element "not last element" all the below elements fields 'bus, dpt' are being null, but if i remove last array element it is working fine,
please guys advice me how to fix that,
Thanks
Array's element schema
partSchema = new SimpleSchema({
emp_id: {
type: String,
optional: false,
autoform: {
type: "select2",
options: function () {
return Meteor.users.find({}).map(function (obj) {
return {label: obj.profile.firstname, value: obj._id};
});
},
}
},
bus: {
optional: false,
type: String,
autoform: {
options: function () {
let emp_id = AutoForm.getFieldValue(this.name.replace('bus', 'emp_id'));
return Bus.find({emp: emp_id}).map(function (obj) {
return {label: obj.bus, value: obj._id};
});
},
}
},
dpt: {
optional: false,
type: String,
autoform: {
options: function () {
let emp_id = AutoForm.getFieldValue(this.name.replace('dpt', 'emp_id'));
return Dpts.find({emp: emp_id}).map(function (obj) {
return {label: obj.dpt, value: obj._id};
})
},
}
},
});
Main schema which am using the array
mainSchema = new SimpleSchema({
other fields...,
parts: {
type: [partSchema],
optional: false,
}
});
result
"parts": [
{
"emp_id": "emp_id1",
"bus": "bsID1",
"dpt": "dpID1",
},
{
"emp_id": "emp_id2",
"bus": "bsID2",
"dpt": "dpID2",
},
{
"emp_id": "emp_id3",
"bus": "bsID3",
"dpt": "dpID3"
},
{
"emp_id": "emp_id4",
"bus": "bsID4",
"dpt": "dpID4"
}
]
Hi @fashkl
I really can't follow. Is this array used for autoform options?
Hi @jankapunkt , thanks for your help,
I have edited description & attached schema code to be more clear,
Thank you @fashkl could you also please add the Autoform version that you use and a short code example of your #autoForm or >quickForm Template so I can start reproducing the Error
Thank you in advance @jankapunkt , Autoform version 5.8.1 and using quickForm, but after deep searching i got the problem that i'm using AutoForm.getFieldValue('emp_id') to set others fields, so when i remove element not last element for EX: index 0, AutoForm.getFieldValue('emp_id ' ==> 2) returns undefined, related to problem #833
@fashkl is there something that prevents you from updating to 7.0.0? The issue should then be fixed.
@fashkl friendly ping.