Form icon indicating copy to clipboard operation
Form copied to clipboard

Sort Order for initially hidden fields

Open jeffreyjackson opened this issue 10 years ago • 15 comments

What causes targets to show up at the top of a section when they are shown? Ideally, I'd like all of my targets to maintain order with how they are in the JSON file. Am I missing something?

jeffreyjackson avatar Jun 19 '15 16:06 jeffreyjackson

Hi Jeffrey,

They should keep the original location, do you have an example JSON to debug what's going on?

Best,

3lvis avatar Jun 19 '15 16:06 3lvis

this is the forms.json I'm using in basic objc project

{
  "groups": [
    {
      "id": "group-dialysis",
      "title": "Dialysis",
      "sections": [
        {
          "id": "section-dialysis-dialysis",
          "title": "Dialysis",
          "fields": [
            {
              "id": "di_dialysis",
              "title": "Dialysis?",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "N/A",
                  "targets": [
                    {
                      "id": "di_dialysis_type",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_schedule",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_access",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_transfer_type",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_comments",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_transfer_type_details",
                      "action": "hide",
                      "type": "field"
                    },
                    {
                      "id": "di_schedule_specify",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "Yes",
                  "targets": [
                    {
                      "id": "di_dialysis_type",
                      "action": "show",
                      "type": "field"
                    },
                    {
                      "id": "di_schedule",
                      "action": "show",
                      "type": "field"
                    },
                    {
                      "id": "di_access",
                      "action": "show",
                      "type": "field"
                    },
                    {
                      "id": "di_transfer_type",
                      "action": "show",
                      "type": "field"
                    },
                    {
                      "id": "di_comments",
                      "action": "show",
                      "type": "field"
                    }
                  ]
                }
              ]
            },
            {
              "id": "di_dialysis_type",
              "title": "Type",
              "type": "select",
              "hidden": "true",
              "values": [
                {
                  "id": "0",
                  "title": "ACUTE"
                },
                {
                  "id": "1",
                  "title": "Chronic"
                },
                {
                  "id": "2",
                  "title": "Hemodialysis"
                },
                {
                  "id": "3",
                  "title": "Peritoneal"
                }
              ]
            },
            {
              "id": "di_schedule",
              "title": "Schedule",
              "type": "select",
              "hidden": "true",
              "values": [
                {
                  "id": "0",
                  "title": "MWF",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "TTS",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "2",
                  "title": "Other",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "show",
                      "type": "field"
                    }
                  ]
                }
              ]
            },
            {
              "id": "di_schedule_specify",
              "title": "Specify",
              "type": "text",
              "hidden": "true",
              "validations": {
                "required": "true"
              }
            },
            {
              "id": "di_access",
              "title": "Access",
              "type": "select",
              "hidden": "true",
              "values": [
                {
                  "id": "0",
                  "title": "AV Fistula"
                },
                {
                  "id": "1",
                  "title": "Permanent"
                },
                {
                  "id": "2",
                  "title": "Temporary"
                }
              ]
            },
            {
              "id": "di_transfer_type",
              "title": "Transfer Type",
              "type": "select",
              "hidden": "true",
              "values": [
                {
                  "id": "0",
                  "title": "Family",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "company",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "2",
                  "title": "Other",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "show",
                      "type": "field"
                    }
                  ]
                }
              ]
            },
            {
              "id": "di_transfer_type_details",
              "title": "Details",
              "type": "text",
              "hidden": "true",
              "validations": {
                "required": "true"
              }
            },
            {
              "id": "di_comments",
              "title": "Comments",
              "type": "text",
              "hidden": "true"
            }
          ]
        }
      ]
    }
  ]
}

jeffreyjackson avatar Jun 19 '15 17:06 jeffreyjackson

please note that the selection of "other" in both select fields sends the targets to the top of the group. cc @3lvis

jeffreyjackson avatar Jun 19 '15 17:06 jeffreyjackson

@3lvis thanks for your help on this. The client I'm working for finds a lot of promise in using Form, and we are eager to contribute back.

jeffreyjackson avatar Jun 19 '15 17:06 jeffreyjackson

@3lvis any idea on why this is happening? I hope its just some error on my end.

jeffreyjackson avatar Jun 22 '15 17:06 jeffreyjackson

Hey Jeffrey! Looks like a bug in form related to fields hidden by default not playing nicely with targets.

3lvis avatar Jun 22 '15 18:06 3lvis

@3lvis thanks for following up on this.

jeffreyjackson avatar Jun 22 '15 19:06 jeffreyjackson

@jeffreyjackson , @3lvis I've debugged the issue and found out that the problem is in this method:

- (void)fieldWithID:(NSString *)fieldID
includingHiddenFields:(BOOL)includingHiddenFields
         completion:(void (^)(FORMField *field, NSIndexPath *indexPath))completion {

in file FORMData.m For some reason it returns <NSIndexPath: 0xc000000000008016> {length = 2, path = 0 - 1} or null while calculating index path properly. I'm going to check it in deep soon. Stay tuned.

UPD: The code I've mentioned above is being executed simultaneously with this in FORMGroup

- (NSArray *)fields {
    NSMutableArray *array = [NSMutableArray new];

    for (FORMSection *section in self.sections) {
        [array addObjectsFromArray:section.fields];
    }

    return array;
}

And gradually fields start to appear in section.fields one by one, in reversed order.

richardtop avatar Aug 27 '15 15:08 richardtop

Any updates on this? We are evaluating this framework and so far everything seems great, but we ran into this issue were we have some hidden fields initially that are display from a target.

Thanks

bbeckley avatar Nov 18 '16 16:11 bbeckley

@bbeckley To work around this issue, I usually put my hidden fields into a section and then hide that section. This doesn't work as well when fields within the section are hidden and should be shown, but if you structure the JSON with that in mind, you should be able to accomplish what you need.

Section hiding:

{
  "groups": [
    {
      "id": "group-dialysis",
      "title": "Dialysis",
      "sections": [
        {
          "id": "section-dialysis",
          "title": "Dialysis",
          "fields": [
            {
              "id": "di_dialysis",
              "title": "Dialysis?",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "N/A",
                  "default": true,
                  "targets": [
                    {
                      "id": "section-dialysis-yes",
                      "action": "hide",
                      "type": "section"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "Yes",
                  "targets": [
                    {
                      "id": "section-dialysis-yes",
                      "action": "show",
                      "type": "section"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "id": "section-dialysis-yes",
          "title": "Dialysis - YES",
          "hidden": true,
          "fields": [
            {
              "id": "di_dialysis_type",
              "title": "Type",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "ACUTE"
                },
                {
                  "id": "1",
                  "title": "Chronic"
                },
                {
                  "id": "2",
                  "title": "Hemodialysis"
                },
                {
                  "id": "3",
                  "title": "Peritoneal"
                }
              ]
            },
            {
              "id": "di_schedule",
              "title": "Schedule",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "MWF",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "TTS",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "2",
                  "title": "Other",
                  "targets": [
                    {
                      "id": "di_schedule_specify",
                      "action": "show",
                      "type": "field"
                    }
                  ]
                }
              ]
            },
            {
              "id": "di_schedule_specify",
              "title": "Specify",
              "type": "text",
              "hidden": "true",
              "validations": {
                "required": "true"
              }
            },
            {
              "id": "di_access",
              "title": "Access",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "AV Fistula"
                },
                {
                  "id": "1",
                  "title": "Permanent"
                },
                {
                  "id": "2",
                  "title": "Temporary"
                }
              ]
            },
            {
              "id": "di_transfer_type",
              "title": "Transfer Type",
              "type": "select",
              "values": [
                {
                  "id": "0",
                  "title": "Family",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "1",
                  "title": "company",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "hide",
                      "type": "field"
                    }
                  ]
                },
                {
                  "id": "2",
                  "title": "Other",
                  "targets": [
                    {
                      "id": "di_transfer_type_details",
                      "action": "show",
                      "type": "field"
                    }
                  ]
                }
              ]
            },
            {
              "id": "di_transfer_type_details",
              "title": "Details",
              "type": "text",
              "validations": {
                "required": "true"
              }
            },
            {
              "id": "di_comments",
              "title": "Comments",
              "type": "text"
            }
          ]
        }
      ]
    }
  ]
}

jeffleeismyhero avatar Nov 21 '16 03:11 jeffleeismyhero

@bbeckley: Please give this branch a try: https://github.com/hyperoslo/Form/tree/hidden_field_order

jeffleeismyhero avatar Nov 21 '16 06:11 jeffleeismyhero

Great. Give me a few hours and I'll pull this and give it a try.

Thanks

On Mon, Nov 21, 2016, 12:14 AM Jeffrey Lee [email protected] wrote:

@bbeckley https://github.com/bbeckley: Please give this branch a try: https://github.com/hyperoslo/Form/tree/hidden_field_order

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hyperoslo/Form/issues/429#issuecomment-261852770, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfjPifxVAKqeVaBc-aduQvupQqVNFLgks5rATargaJpZM4FHVm3 .

bbeckley avatar Nov 21 '16 13:11 bbeckley

Thanks Jeffrey,

This seemed to fix the sort order for initially hidden fields based off my orginal JSON structure (I did build my form with more sections based off your first email with hiding /showing them, which worked). A couple of side notes that I noticed now with your branch, but I should be able to work around or possible I have configured wrong in my JSON which I will investigate more later:

  1. In my form section where my hidden fields are, once they become "visible" they are now displayed in the correct order but the section divider line gets lost. Please see screenshots before/after
    • Before: https://drive.google.com/open?id=0BxD9vnTIOf3qeFczVG1jSnV3cVU
    • After: https://drive.google.com/open?id=0BxD9vnTIOf3qWkFRUXFWY1BYTjA
  2. The segment controller for id "work-comp-claim-filed" which shows/hides the additional fields doesn't stay selected when "Yes" is selected. The first time you selected "Yes" the targets run and the segment is highlighted for that duration then becomes not highlighted. If I selected "Yes" again it stays highlighted. If I select "No", no stays highlighted.

I appreciate the help and think I can continue working on the form, based off your branch or hiding sections. The above issues aren't show stoppers for me but if you have suggests or fixes I would be happy to test them. I attached a sample of my JSON in case you are curious.

{ "groups": [ { "id": "condition-causing-disability", "title": "Condition Causing Disability", "sections": [ { "id": "condition-info", "fields": [ { "id": "claim_reason", "title": "Type", "type": "select", "size": { "width": 100, "height": 1 }, "values": [ { "id": "disability_type_default", "title": "-Select-", "default": true, "targets": [ { "id": "disability_description_mva", "type": "field", "action": "hide" }, { "id": "disability_description_sick", "type": "field", "action": "hide" }, { "id": "disability_description_work_related", "type": "field", "action": "hide" },

                {
                  "id":

"condition-causing-disability-workrelated-question", "type": "section", "action": "show" } ] }, { "id": "1", "title": "Motor Vehicle Accident", "targets": [ { "id": "disability_description_mva", "type": "field", "action": "show" }, { "id": "disability_description_sick", "type": "field", "action": "hide" }, { "id": "disability_description_work_related", "type": "field", "action": "hide" },

                {
                  "id":

"condition-causing-disability-workrelated-question", "type": "section", "action": "show" } ] }, { "id": "2", "title": "Sickness", "targets": [ { "id": "disability_description_mva", "type": "field", "action": "hide" }, { "id": "disability_description_sick", "type": "field", "action": "show" }, { "id": "disability_description_work_related", "type": "field", "action": "hide" },

                {
                  "id":

"condition-causing-disability-workrelated-question", "type": "section", "action": "show" } ] }, { "id": "3", "title": "Work Related Injury/Sickness", "targets": [ { "id": "disability_description_mva", "type": "field", "action": "hide" }, { "id": "disability_description_sick", "type": "field", "action": "hide" }, { "id": "condition-causing-disability-workrelated-question", "type": "section", "action": "show" }, { "id": "disability_description_work_related", "type": "field", "action": "show" } ] }, { "id": "4", "title": "Other", "targets": [ { "id": "disability_description_mva", "type": "field", "action": "show" }, { "id": "disability_description_sick", "type": "field", "action": "hide" }, { "id": "disability_description_work_related", "type": "field", "action": "hide" },

                {
                  "id":

"condition-causing-disability-workrelated-question", "type": "section", "action": "show" } ] } ] }, { "id": "disability_description_mva", "title": "Please describe in detail how, when and where the accident occured.", "type": "text", "hidden": true, "size": { "width": 100, "height": 1 } }, { "id": "disability_description_sick", "title": "Please describe in detail the nature of your sickness/condition and its first symptoms.", "type": "text", "hidden": true, "size": { "width": 100, "height": 1 } }, { "id": "disability_description_work_related", "title": "Please describe the cause of the injury/sickness.", "type": "text", "hidden": true, "size": { "width": 100, "height": 1 } } ] }, { "id": "condition-causing-disability-workrelated-question", "fields": [ { "id": "work-comp-claim-filed", "title": "Have you filed/do you intent to file a Workers Compensation Claim?", "type": "segment", "hidden": false, "validations": { "required": true }, "size": { "width": 100, "height": 1 }, "values": [ { "id": "yes", "title": "Yes", "targets": [ { "id": "work-comp-ins-carrier-name", "type": "field", "action": "show" }, { "id": "work-comp-ins-carrier-address", "type": "field", "action": "show" }, { "id": "work-comp-ins-carrier-city", "type": "field", "action": "show" }, { "id": "work-comp-ins-carrier-state", "type": "field", "action": "show" }, { "id": "work-comp-ins-carrier-zip", "type": "field", "action": "show" } ] }, { "id": "no", "title": "No", "targets": [ { "id": "work-comp-ins-carrier-name", "type": "field", "action": "hide" }, { "id": "work-comp-ins-carrier-address", "type": "field", "action": "hide" }, { "id": "work-comp-ins-carrier-city", "type": "field", "action": "hide" }, { "id": "work-comp-ins-carrier-state", "type": "field", "action": "hide" }, { "id": "work-comp-ins-carrier-zip", "type": "field", "action": "hide" } ] } ] }, { "id": "work-comp-ins-carrier-name", "title": "Carrier Name", "hidden": true, "type": "text", "size": { "width": 100, "height": 1 }, "validations": { "required": true, "min_length": 2 } }, { "id": "work-comp-ins-carrier-address", "title": "Carrier Address", "hidden": true, "type": "text", "size": { "width": 100, "height": 1 }, "validations": { "required": true, "min_length": 2 } }, { "id": "work-comp-ins-carrier-city", "title": "City", "hidden": true, "type": "text", "size": { "width": 100, "height": 1 }, "validations": { "required": true, "min_length": 2 } }, { "id": "work-comp-ins-carrier-state", "title": "State", "hidden": true, "type": "text", "size": { "width": 100, "height": 1 }, "validations": { "required": true, "min_length": 2 } }, { "id": "work-comp-ins-carrier-zip", "title": "Zip", "hidden": true, "type": "number", "size": { "width": 100, "height": 1 }, "validations": { "required": true, "min_length": 5, "max_length": 5 } } ] }, { "id": "condition-causing-disability-dates", "fields": [ { "id": "work-comp-treated-date", "title": "Date you were first treated", "hidden": false, "type": "date", "size": { "width": 100, "height": 1 }, "validations": { "required": true } }, { "id": "work-comp-last-worked-date", "title": "Last day worked prior to disability", "hidden": false, "type": "date", "size": { "width": 100, "height": 1 }, "validations": { "required": true } }, { "id": "work-comp-full-day", "title": "Did you work a full day?", "type": "segment", "hidden": false, "validations": { "required": true }, "size": { "width": 100, "height": 1 }, "values": [ { "id": "yes", "title": "Yes" }, { "id": "no", "title": "No" } ] } ] } ] } ] }

On Mon, Nov 21, 2016 at 7:07 AM, Brandon Beckley [email protected] wrote:

Great. Give me a few hours and I'll pull this and give it a try.

Thanks

On Mon, Nov 21, 2016, 12:14 AM Jeffrey Lee [email protected] wrote:

@bbeckley https://github.com/bbeckley: Please give this branch a try: https://github.com/hyperoslo/Form/tree/hidden_field_order

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hyperoslo/Form/issues/429#issuecomment-261852770, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfjPifxVAKqeVaBc-aduQvupQqVNFLgks5rATargaJpZM4FHVm3 .

bbeckley avatar Nov 21 '16 19:11 bbeckley

Hi Brandon,

2. The segment controller for id "work-comp-claim-filed" which shows/hides the additional fields doesn't stay selected when "Yes" is selected. The first time you selected "Yes" the targets run and the segment is highlighted for that duration then becomes not highlighted. If I selected "Yes" again it stays highlighted. If I select "No", no stays highlighted.

This issue should be resolved in that same branch. Please test it out and let me know if you still have the same issue.

I am still looking into the separator issue you identified in part 1.

jeffleeismyhero avatar Nov 22 '16 00:11 jeffleeismyhero

Works great. The segment stays highlighted on first click after the targets run. Again, appreciated the quick responses and help with the fixes.

Thanks

On Mon, Nov 21, 2016 at 6:38 PM, Jeffrey Lee [email protected] wrote:

Hi Brandon,

2. The segment controller for id "work-comp-claim-filed" which shows/hides the additional fields doesn't stay selected when "Yes" is selected. The first time you selected "Yes" the targets run and the segment is highlighted for that duration then becomes not highlighted. If I selected "Yes" again it stays highlighted. If I select "No", no stays highlighted.

This issue should be resolved in that same branch. Please test it out and let me know if you still have the same issue.

I am still looking into the separator issue you identified in part 1.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hyperoslo/Form/issues/429#issuecomment-262112903, or mute the thread https://github.com/notifications/unsubscribe-auth/AGfjPr9_oqZ4uDSwT8z1qIhfz4sOJZ2Rks5rAjmQgaJpZM4FHVm3 .

bbeckley avatar Nov 22 '16 15:11 bbeckley