meteor-autoform icon indicating copy to clipboard operation
meteor-autoform copied to clipboard

Array of objects set last object fields to null when remove unordered element

Open fashkl opened this issue 5 years ago • 6 comments

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"
    }
  ]

fashkl avatar Nov 12 '20 13:11 fashkl

Hi @fashkl

I really can't follow. Is this array used for autoform options?

jankapunkt avatar Nov 13 '20 14:11 jankapunkt

Hi @jankapunkt , thanks for your help,

I have edited description & attached schema code to be more clear,

fashkl avatar Nov 14 '20 08:11 fashkl

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

jankapunkt avatar Dec 04 '20 06:12 jankapunkt

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 avatar Dec 05 '20 18:12 fashkl

@fashkl is there something that prevents you from updating to 7.0.0? The issue should then be fixed.

jankapunkt avatar Jan 30 '21 17:01 jankapunkt

@fashkl friendly ping.

jankapunkt avatar Feb 18 '21 08:02 jankapunkt