XLForm detect change to row value

3.7k Views Asked by At

I'm starting to use the very excellent XLForm project (https://github.com/xmartlabs/XLForm) for iOS, however I've run into something that could possibly really easy to answer yet I can't figure it out.

I want to detect the change in a row's value - for example a text field or a segmented control. What method do I need to implement to catch this change? I'm guessing that it comes from the controls themselves but I'm not clear exactly how to get at it since XLForm manages the controls.

Thanks very much!

4

There are 4 best solutions below

0
On
-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue{

}
0
On
0
On

For Swift:

override func formRowDescriptorValueHasChanged(formRow: XLFormRowDescriptor!, oldValue: AnyObject!, newValue: AnyObject!) {

print("changed!")

}
0
On

Dont forget calling the

[super formRowDescriptorValueHasChanged:oldValue:newValue]

Here's the example from above

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue
{
    // super implementation MUST be called
    [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue];

    if ([formRow.tag isEqualToString:@"alert"]){
        if ([[oldValue valueData] isEqualToNumber:@(0)] == NO && [[newValue valueData] isEqualToNumber:@(0)]){
            [self.form removeFormRow:formRow];
        }
    }
}