xmartlabs / XLForm

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
MIT License
5.77k stars 953 forks source link

inline date picker with minuteInterval/minimumDate/maximumDate #73

Closed bhirt-bpl closed 9 years ago

bhirt-bpl commented 10 years ago

I need to set min/max dates and an interval for the selection. I can't seem to figure out how to do this with the current master branch. I've added some properties to XLFormDateCell to control these and updated setModeToDatePicker: to set the options on the date picker.

-(void)setModeToDatePicker:(UIDatePicker *)datePicker
{
    if ((([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDateInline] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDate]) && self.formDatePickerMode == XLFormDateDatePickerModeGetFromRowDescriptor) || self.formDatePickerMode == XLFormDateDatePickerModeDate){
        datePicker.datePickerMode = UIDatePickerModeDate;
    }
    else if ((([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTimeInline] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTime]) && self.formDatePickerMode == XLFormDateDatePickerModeGetFromRowDescriptor) || self.formDatePickerMode == XLFormDateDatePickerModeTime){

        datePicker.datePickerMode = UIDatePickerModeTime;
    }
    else{
        datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    }

    if (self.minuteInterval)
        datePicker.minuteInterval = self.minuteInterval;

    if (self.minimumDate)
        datePicker.minimumDate = self.minimumDate;

    if (self.maximumDate)
        datePicker.maximumDate = self.maximumDate;

}

Then in my form setup I can do this to get the desired effect:

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"ends" rowType:XLFormRowDescriptorTypeTimeInline title:@"Ends"];
row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*25];
XLFormDateCell * dateEndCell = (XLFormDateCell *)[row cellForFormController:self];
dateEndCell.minuteInterval = 15;
dateEndCell.minimumDate = start;

If there is another way to do this without modifying the XLForm code, let me know. If this feature isn't currently supported and my solution seems acceptable to you, I can submit a pull request.

screenshot_835

bhirt-bpl commented 10 years ago

I ended up creating a pull request for this feature and a couple of other minor update here https://github.com/xmartlabs/XLForm/pull/74

afnanahmad commented 9 years ago

@bhirt-bpl You can set minimum date or maximum date like this.

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"ends" rowType:XLFormRowDescriptorTypeTimeInline title:@"Ends"];
row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*25];
[row.cellConfigAtConfigure setValue:[[NSDate date] dateBySubtractingYears:13] forKey:@"maximumDate"];
[row.cellConfigAtConfigure setValue:[[NSDate date] dateBySubtractingYears:20] forKey:@"minimumDate"];
brianfox201 commented 8 years ago

Can we change min/max date properties run time ? I have 2 inline datepickers. I want to change the min/max property of second date picker based on value of first date picker. So I have added row.cellConfigAtConfigure code in formrowvaluechanged method. But its not working.

JerryWang761208 commented 7 years ago

Instead of using row.cellConfigAtConfigure... I try to use the following, and it works.

[row.cellConfig setObject:minimumDate_you_want forKey:@"minimumDate"];
i-am-chris commented 7 years ago

@brianfox201 did you have any success with that?? I am looking for the same thing.

ManiRelavant commented 1 year ago

NSDate currentDate = [NSDate date]; NSDictionary dict = @{ @"datePicker.maximumDate" : currentDate }; [row.cellConfigAtConfigure addEntriesFromDictionary: dict];

try to use