nicklockwood / FXForms

[DEPRECATED]
Other
2.93k stars 339 forks source link

Indexed table for FxFormFieldOptions #388

Open federico-f opened 9 years ago

federico-f commented 9 years ago

My FxFormFieldOptions have many items, so the table that is presented to the user is very long and requires substantial scrolling (and patience!).

Is there any way to add index sections or a search box to the table? A new property would be great, but I would not mind to do it myself, if it can be done in a "clean" (i.e. not messing with your code) way.

Any hints? Thanks!

nicklockwood commented 9 years ago

Therr are two simple options:

1) add headers to separate the table into groups by adding FXFormFieldHeader values (see the registration form example)

2) split the form into nested subforms, which you can do by splitting your form object up into several sub objects (again, see the registration form)

Implementing a search filter is possible, but there's no support built in. You'd need to override the fields method of your form and return a filtered list based on a search string.

federico-f commented 9 years ago

Thank you for your reply, Nick. I am not talking about the "main" form, I am referring to the tableview that gets automatically displayed in a new view controller to pick up one of the options. In the registration form example, in the Country field, imagine having not just a few countries, but all of them... I would like a way to quickly navigate that list, via index sections or a search box. Do you think it's possible? Thank you. ios simulator screen shot 25 giu 2015 07 33 09

neilkimmett commented 8 years ago

I'm a bit stumped on this too. I can figure out how to add FXFormFieldHeader values to the fields of a form, and thus get the A..Z index on the side of the form, but I can't figure out how to add them to the options of a field of a form (that then gets presented as a new controller on the stack). Any further pointers?

neilkimmett commented 8 years ago

OK I've done some more digging and I think I need to be poking around in here? https://github.com/nicklockwood/FXForms/blob/master/FXForms/FXForms.m#L1421-L1429

neilkimmett commented 8 years ago

Right so I managed to horribly hack in sectioning-by-first-letter in to the above by replacing the lines referenced in my previous comment with

NSString *currentHeader = @"";
for (NSUInteger i = 0; i < [field.options count]; i++)
{
    NSInteger index = i + (field.placeholder? 1: 0);
    NSString *title = [field optionDescriptionAtIndex:index];
    NSString *firstChar = [title substringToIndex:1];

    NSMutableDictionary *field = [@{FXFormFieldKey: [@(index) description],
                                   FXFormFieldTitle: title,
                                   FXFormFieldType: FXFormFieldTypeOption,
                                   FXFormFieldAction: action} mutableCopy];
    if (![currentHeader isEqualToString:firstChar]) {
        field[FXFormFieldHeader] = firstChar;
        currentHeader = firstChar;
    }
    [fields addObject:field];
}
_fields = fields;

But I still didn't get the A-Z jump bar down the side because sectionIndexTitlesForTableView: and tableView:sectionForSectionIndexTitle:atIndex: aren't implemented. But hopefully this gives a very vague idea of what I was trying to achieve? Not suggesting the above code is a good idea at all, mostly just recording this here for my own posterity.