Open mmarbouh opened 7 years ago
Hi @mmarbouh, I was trying to reproduce your issue but got a bit confused, also the JSON that you provided doesn't work out of the box with the demo project since it needs a few custom fields. Could you please provide a sample project that shows the problem?
Thanks in advance :)
Hi,
The Issue
I am trying to automate the process of filling form field data based on data present in other fields. Basically, implement a rules engine of sorts into forms. For example, if a checkbox gets checked, it'll hide a specific field further down the line, and vice versa if it's unchecked.
The logic behind this is already fleshed out, and functional, but only when the form isn't too big so that there are non-visible fields. I.e., if there's fields at the bottom of the form that one has yet to scroll through, and I attempt to update any field (visible or otherwise) through the use of FORMTargets, a NSInternalInconsistency exception is thrown. That the number of items before the update must be equal to after the update plus or minus the modifications.
The Code
data.json.txt
Attached you will find a very simple json to demo this on, as of this writing (August 21st, 2017), I am on the latest version of the engine, and am using the demo HYPSampleCollectionViewController from the Basic-ObjC scheme, I am just swapping out the filename.
- (void)checkRules { FORMField *field = [self.dataSource fieldWithID:@"check" includingHiddenFields:YES]; NSMutableArray *targets = [NSMutableArray array];
}
Above is the code I use to check the current field values and generate targets accordingly. This is called in every field's
fieldUpdatedBlock
.So yeah, as mentioned, the code does work, it's just that when there's fields out of view that the number of items somehow gets corrupted after/while processing the targets. If I modify my json to only have one group, so that it can all fit on the screen without having to scroll, then there are no issues.
For example, here is the exception logged when attempting to toggle the "Is Juvenile?" switch:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (4) must be equal to the number of items contained in that section before the update (4), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).' *** First throw call stack:
Thank you in advance for any insight you could provide.