XLForm - dynamically add rows based of user input

451 Views Asked by At

I'm trying to add more rows in my form based on the user's input.

For example, I have a field asking for how many rows I want to add to the form. If the input is 5, then 5 additional rows will be generated and appended to the form.

As of now XLForm has the ability to add a single row (e.g. multivalue form), I was thinking if I can do the same but in bulk instead of just adding a single row each time.

Is this possible?

1

There are 1 best solutions below

0
On

It's been a while since I handled XLForm, but I think something like this will work fine:

-(void) formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue {
    [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue];

    NSNumber *newVal = [newValue valueData];

    int count = newVal.intValue; //5

    for(int i=0; i<count; i++) {
        NSString *title = [NSString stringWithFormat:@"title %d",i+1];
        XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:title rowType:XLFormRowDescriptorTypeText];
        [row.cellConfigAtConfigure setObject:title forKey:@"textField.placeholder"];
        [self.form addFormRow:row afterRowTag:someOtherRow.tag];
    }
}