vendredi 7 août 2020

Using JSON object values in javascript to change values for another JSON object

So I'm trying to use values in a JSON object (Object A) to check if another object (Object B) will show or not. I can't just instantiate the information due to the other data sets, right? So I have this:

if (data['Date-Returned-to-work'].day.placeholder == "--" &&
data['Date-Returned-to-work'].month.placeholder) == "--" &&
data['Date-Returned-to-work'].year.placeholder) == '----") {
    show = 'false';
}else {
    show = 'true';
}

However, it isn't changing the value when placed in Object B's spot for conditional statements. Here's a section Object A.

"label": "Date Returned to work (if not returned to work, please explain & detail expected return to work date)",
                "hideInputLabels": false,
                "inputsLabelPosition": "top",
                "fields": {
                    "day": {
                        "placeholder": "--",
                        "hide": false,
                        "type": "number",
                        "required": true
                    },
                    "month": {
                        "placeholder": "--",
                        "hide": false,
                        "type": "select",
                        "required": true
                    },
                    "year": {
                        "placeholder": "----",
                        "hide": false,
                        "type": "number",
                        "required": true
                    }
                },
                "useLocaleSettings": false,
                "mask": false,
                "tableView": true,
                "alwaysEnabled": false,
                "type": "day",
                "input": true,
                "key": "Date-Returned-to-work",
                "validate": {
                    "customMessage": "",
                    "json": ""
                },
                "conditional": {
                    "show": "",
                    "when": "",
                    "json": ""
                },
                "encrypted": false,
                "maxDate": "",
                "minDate": "",
                "properties": {},
                "customConditional": "",
                "logic": [],
                "attributes": {},
                "tags": [],
                "reorder": false
            }

and here is Object B

label: "if not returned",
allowMultipleMasks: false,
showWordCount: false,
showCharCount: false,
tableView: true,
alwaysEnabled: false,
type: "textfield",
input: true,
key: "if-not-returned",
defaultValue: "",
-validate: {
customMessage: "",
json: ""
},
-conditional: {
show: "",
when: "",
json: ""
},
-properties: {
},
-tags: [
],
inputFormat: "plain",
encrypted: false,
customConditional: "if (data['Date-Returned-to-work'].day.placeholder == "--" &&
    data['Date-Returned-to-work'].month.placeholder == "--" &&
    data['Date-Returned-to-work'].year.placeholder == "----") {
        show = false;
    } else {
        show = true;
    }",
-logic: [
],
-attributes: {
},
-widget: {
type: ""
},
reorder: false

Basically, I want to make "show: false" when a user leaves a field with the default (placeholder) values. All help is appreciated. Changing JSON values like this is new-ish to me.

Aucun commentaire:

Enregistrer un commentaire