1

So I have this form, which pushes a subform for gathering mailing address info (I've simplified the JSON definition of the form here for clarity - I did test this version, and it still breaks):

{
    "grouped": true,
    "title": "Add",
    "sections": [
                 { "elements":[
                               { "type":"QLabelElement", "title":"Location",
                               "sections": [
                                            {
                                             "elements": [ { "type":"QEntryElement", "title":"Address line 1","placeholder":"", "bind":"textValue:Address1", "key":"Address1"},
                                                         { "type":"QEntryElement", "title":"Address line 2","placeholder":"optional", "bind":"textValue:Address2", "key":"Address2"},
                                                         { "type":"QEntryElement", "title":"City","placeholder":"", "bind":"textValue:City", "key":"City"},
                                                         { "type":"QEntryElement", "title":"State/Province","placeholder":"", "bind":"textValue:StateProvRegion", "key":"Prov"},
                                                         { "type":"QEntryElement", "title":"ZIP/Postal Code","placeholder":"", "bind":"textValue:PostalCode", "key":"PCode"},
                                                         { "type":"QPickerElement", "title":"Country", "items":[["Czech Republic", "Germany", "United Kingdom"]], "value":"Czech Republic"}
                                                         ]
                                            }]
                               }
                               ]
                 }
                 ]
}

I have an NSMutableDictionary with a bunch of data in it to pre-pop all the fields in the form, including those in the address. The code to populate the dictionary and show the dialog looks like this (again, super-simplified, but this still breaks):

NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];

[dataDict setObject:@"123 Maple Street" forKey:@"Address1"];

QRootElement *root = [[QRootElement alloc] initWithJSONFile:@"addjobform" andData:dataDict];

UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];

If I run this code with the JSON above, the dialog comes up fine, but the fields don't populate. BUT - if I move the address elements out of the nested subform back up to the first level - they populate (in this case, Address1 comes up with 123 Maple Street pre-popped). In other words, this JSON binds correctly while the previous version above doesn't:

{
    "grouped": true,
    "title": "Add",
    "sections": [{
                 "elements": [ { "type":"QEntryElement", "title":"Address line 1","placeholder":"", "bind":"textValue:Address1", "key":"Address1"},
                              { "type":"QEntryElement", "title":"Address line 2","placeholder":"optional", "bind":"textValue:Address2", "key":"Address2"},
                              { "type":"QEntryElement", "title":"City","placeholder":"", "bind":"textValue:City", "key":"City"},
                              { "type":"QEntryElement", "title":"State/Province","placeholder":"", "bind":"textValue:StateProvRegion", "key":"Prov"},
                              { "type":"QEntryElement", "title":"ZIP/Postal Code","placeholder":"", "bind":"textValue:PostalCode", "key":"PCode"},
                              { "type":"QPickerElement", "title":"Country", "items":[["Czech Republic", "Germany", "United Kingdom"]], "value":"Czech Republic"}
                              ]
                 }
                 ]
}

Why do the bindings work at the first level and not nested under the Location label? The form push works as advertised, but the binding is broken - is there something special I have to be doing? I've searched far and wide and not found an answer or an example. I tried this code in a stripped down single-view app that does nothing but the above, and it still breaks - so it's not an interaction with my other code either. Per the author of QuickDialog, subform nesting is supposed to be supported (https://github.com/escoz/QuickDialog/issues/226) Any thoughts? Thanks!

belvario
  • 13
  • 2

1 Answers1

0

By default QuickDialog does what's called a "shallow" bind, where only the first level of elements get bound. This is helpful because you can control when the forms get updated, without having to define every form as a different JSON file.

Every QElement has a shallowBind property that defaults to YES. If you change it to no, binding will continue up until the next layer. So in your case, what you want is to tell QuickDialog that the QLabelElement should not follow a shallow bind, like:

{"type":"QLabelElement", "shallowBind":false, "title":"Location", ...

This tells the parent section that when it is binding to an object, it should also go into this element.

Eduardo Scoz
  • 24,653
  • 6
  • 47
  • 62
  • Thanks Eduardo. QD is awesome, saving me a lot of headache :) I figured I had to be doing something wrong here - that fixed it. Is there a good comprehensive documentation source anywhere for QD, like a wiki? I feel like I am flying a bit blind so far, though it's not too bad working from the sample code. I don't think something like this issue is covered in the samples though, is it? – belvario Apr 10 '14 at 17:35
  • There's not a lot of docs, no. I never had time to write it, and nobody ever really helped on that. The samples cover the vast majority of features, but likely not this one, as I ended up adding it very recently. – Eduardo Scoz Apr 10 '14 at 18:35