Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fashkl opened this issue Nov 12, 2020 · 6 comments
Open

Comments

@fashkl
Copy link

fashkl commented Nov 12, 2020

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"
    }
  ]
@jankapunkt
Copy link
Member

Hi @fashkl

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

@fashkl
Copy link
Author

fashkl commented Nov 14, 2020

Hi @jankapunkt , thanks for your help,

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

@jankapunkt
Copy link
Member

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

@fashkl
Copy link
Author

fashkl commented Dec 5, 2020

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

@jankapunkt
Copy link
Member

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

@jankapunkt
Copy link
Member

@fashkl friendly ping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants