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

dependsOn in array is not working properly with resolver #107

Open
KiSchulte opened this issue Oct 5, 2017 · 4 comments
Open

dependsOn in array is not working properly with resolver #107

KiSchulte opened this issue Oct 5, 2017 · 4 comments

Comments

@KiSchulte
Copy link

KiSchulte commented Oct 5, 2017

Hi,

I've created a Form with couple of array's. One of them has three dropdown where the second depends on the first and the third on the second.
I've created a resolver for this to get the right values for the dropdowns from a existing hierarchical object with three dimensions.
This is working like expected so far.
But the datastore is not updated like it should.

After I added the first item in the array, all three values are present in the datastore if I check them with getData(). Then with adding the next item, the issue starts. After adding the item to the array the previous entry in the datastore has no property two and three anymore, booth are deleted by adding the next item to the array.

First item added:
{ "gender": "Female", "services": [ { "category": "Beauty & Wellness", "service": "Beauty Salon", "specialization": "Nail Salon" } ] }

Next Item added
{ "gender": "Female", "services": [ { "category": "Beauty & Wellness" }, { "category": "Beauty & Wellness", "service": "Hairdresser" } ] }

And this repeats on every adding. Only the last added item has the properties two and three the previous one are losing the properties.

Here is my resolver:
` const resolver = function(names, data, cb) {
let schemas = [];
let schema = [];

        let i = data.services.length - 1;
        let category = data.services[i].category;
        let serviceDef = false;
        if (names[0] === '$.services[#].specialization' && data.services[i].hasOwnProperty('service')) {
            serviceDef = data.services[i].service;
        }

        let serviceObj = [];

        if (names[0] === '$.services[#].service' && services[category]) {
            schema.type = "string";
            Object.keys(services[category]["services"]).forEach(function(key, value) {
                serviceObj.push(key);
            },services[category]["services"]);
        } else if (serviceDef && services[category]['services'][serviceDef]) {
            schema.type = "string";
            services[category]['services'][serviceDef]["specializations"].forEach(function(key, value) {
                serviceObj.push(key);
            });
        }
        if (serviceObj.length === 0) schema.type = null;
        schema.enum = serviceObj;
        schemas[names[0]] = schema;
        setTimeout(function(){cb(schemas)},500);
    };

`

This resolver handles booth dropdown dependencies. I tried already to use the selector '$.services[$].service' instead of '$.services[#].service', so I thought this will just catch the last element in the array, but with this the dependencies are not builded correctly anymore.

I hope I can manage to set up a jsfiddle environment with the whole setting, so it will be easier to check it. Maybe it's also a problem in my resolver, maybe I set a wrong schema here?

Any help will be appreciated.

cheers

@KiSchulte KiSchulte changed the title dependsOn in array is not working properly dependsOn in array is not working properly with resolver Oct 5, 2017
@KiSchulte
Copy link
Author

Ok, I had a deeper look into the topic. Seems that this will not work at all at the moment. As there is no information about the added array Elements in the schemaMap, there is no possibility to address the certain array element. Which results in the issue that for cleanData the id of the array is given and therefore all array elements are cleaned up on dependencyChange and not only the actual chosen one. The only solution I see here, to fix this, is to integrate array Elements in the schemaMap and add the id in the input.

@stutteringp0et
Copy link

I'm in the same boat here...

@stutteringp0et
Copy link

I altered onDependencyChanged to add the source variable to the shemaresolver output, but it's pretty useless. the source element ID doesn't reflect the heirarchy of the data attributes.

@idelvall
Copy link
Member

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

No branches or pull requests

3 participants