xmartlabs/XLForm

minimum value

Closed this issue ยท 2 comments

Hello.
Please take a look at this:
in my form i have this definition:

 XLFormDescriptor *form;
 XLFormSectionDescriptor *section;
 XLFormRowDescriptor *row;
  
    
 form = [XLFormDescriptor formDescriptorWithTitle:@"Add Event"];
 section = [XLFormSectionDescriptor formSectionWithTitle:@"add dates"];
[form addFormSection:section];

NSDate *plus14daysMinus3h = [NSDate dateWithTimeIntervalSinceNow:((14*24*3600)-(3*3600))];
NSDate *minimum3hFromNow = [NSDate dateWithTimeIntervalSinceNow:(3*3600)];

//FROM DATE
row = [XLFormRowDescriptor formRowDescriptorWithTag:f1_from rowType:XLFormRowDescriptorTypeDateTime title:@"From"];
NSDate *now0 = [NSDate date];
NSCalendar *calendar0 = [NSCalendar currentCalendar];

[row.cellConfigAtConfigure setObject:minimum3hFromNow forKey:@"minimumDate"];
[row.cellConfigAtConfigure setObject:plus14daysMinus3h forKey:@"maximumDate"];
row.required = YES;
[section addFormRow:row];


//TO DATE
row = [XLFormRowDescriptor formRowDescriptorWithTag:f1_to rowType:XLFormRowDescriptorTypeDateTime title:@"To"];
NSDate *now1 = [NSDate date];
[row.cellConfigAtConfigure setObject:plus14days forKey:@"maximumDate"];
[row.cellConfigAtConfigure setObject:now1 forKey:@"minimumDate"];
[section addFormRow:row];

XLFormRowDescriptor *buttonRow = [XLFormRowDescriptor formRowDescriptorWithTag:@"submitButton" rowType:XLFormRowDescriptorTypeButton title:@"SEND REQUEST"];
    //buttonRow.action.formSelector = @selector(dismissModalView);
    buttonRow.action.formSelector = @selector(validateForm1);
 [section addFormRow:buttonRow];

NOW I HAVE THIS PROBLEM:
I need to modify the minimum date on the TO (second row) to be the row1.value + 3h
so i proceed to do:

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
[super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
 if([rowDescriptor.tag isEqualToString:@"f1_from"])
    {
        //NSString * evenMoreNewValue = [[NSString alloc] initWithFormat:@"Hi %@ !", newvalue];
        
        //NSDate *mydate = dataVeche;
        NSDate *myDate  = [NSDate new];
        NSTimeInterval secondsIn3Hours = 3 * 60 * 60;
        NSDate *date3hAhead = [myDate dateByAddingTimeInterval:secondsIn3Hours];
        NSLog(@"data in 3 ore este: %@",date3hAhead);
        theNewV1  = newValue;
        NSLog(@"%@",theNewV1);
    }
 if([rowDescriptor.tag isEqualToString:@"f1_to"]) { 
theNewV2 =  [NSDate dateWithTimeInterval:3600*3 sinceDate:theNewV1];
        NSLog(@"๐Ÿ•๐Ÿ•๐Ÿ•๐Ÿ•๐Ÿ• %@",theNewV2);
//[self reloadFormRow:rowDescriptor]; 

//will need to make here the row value to be the minimum - >> :/
//cannot figure it out.
}

Can anyone tell me if this is achievable??
I am struggling with this for 21h stright... may be the lack of sleep ๐Ÿ‘Ž or the brain is dead :)

Hi @i-am-chris,
You can access the row that you want to modify, change its minimum date through cellConfig and then update it it. You can use next code as a snippet:

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

  if([rowDescriptor.tag isEqualToString:@"f1_from"]) {
      // .. add your code to calculate the new minimum date

      XLFormRowDescriptor *row = [self.form formRowWithTag:@"f1_to"];
      [row.cellConfig setValue: theNewV1 forKeyPath:@"minimumDate"];
      [self updateFormRow:row]; // You might need to update the row's value before this line
  }
}

Otherwise, we use our GitHub project for bug reports and feature requests. In the future, you should open questions like this on Stack Overflow and tag xlform.

Thanks, just woke up. @m-revetria you rock!
Did not know how to call a XLFormDescriptor row ... makes sense now.