FXForms icon indicating copy to clipboard operation
FXForms copied to clipboard

Presenting a `FXFormFieldType` as subform.

Open markst opened this issue 9 years ago • 4 comments

I wish to present a subform which is a fullscreen form with one field FXFormFieldTypeLongText. My subform field is part of the model object I'm presenting my initial form from.

I can't seem to create a field without raising the exception: FXFormViewController field value must conform to FXForm protocol

However, I have been able to work up a solution, using a NotesForm proxy class.

             @{FXFormFieldTitle: @"Notes (Optional)",
               FXFormFieldType:  FXFormFieldTypeLongText,
               FXFormFieldClass:[NotesForm class],
               FXFormFieldViewController:[FXFormViewController class],
               FXFormFieldDefaultValue:notesFormField,
               @"textLabel.font":[UIFont proximaNovaRegularFontWithSize:16.0],
               @"textLabel.textColor":[UIColor tn_darkGray],
               }

Am I on the right track? or is there a more straightforward way of presenting a screen with one or more fields that are not part of a new object.

markst avatar Nov 05 '14 06:11 markst

The proxy form seems like the way to go in this case.

You can present a field in a screen on its own, but only by building a custom view controller with a bespoke UI for editing the field value. FXFormViewController is only designed to work with fields whose value is of type FXForm, it can't display a single field.

I could modify FXFormViewController to do this proxying automatically, but it seems like a bit of an edge case, and it's unclear how field properties such as header/footer should be handled in the general case (would they be displayed in both the main form and subform?).

I'll think about it.

nicklockwood avatar Nov 05 '14 09:11 nicklockwood

I would like something like this as well, I have been able to accomplish this goal by just exposing the FXFormField initializer.

I wanted to create a Cell that contained two fields state and zipcode, so what I did was create a custom class to represent the data for the field. then when the user taps on the state label I do this

- (void)didSelectWithTableView:(UITableView *)tableView controller:(UIViewController *)controller {
    FXFormViewController *subForm = [[FXFormViewController alloc] init];

    NSDictionary *attributes = @{FXFormFieldKey: @"stateCode",
                                 FXFormFieldOptions: @[                    @"AL",
                                                                                     [Truncated]
                                                                                             @"WY"],
                                 FXFormFieldValueTransformer: @"USStateValueTransformer"
                                 };

    FXFormField *field = [[FXFormField alloc] initWithForm:self.field.value controller:subForm.formController attributes:attributes];


    [subForm setField:field];

    [controller.navigationController pushViewController:subForm animated:YES];
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:NO];
}

I also overrode -setField like so

- (void)setField:(FXFormField *)field {
    [super setField:field];

    if (!field.value) {
        field.value = [PPStateZip new];
    }
}

that way it uses my new value container.

WestonHanners avatar Nov 21 '14 19:11 WestonHanners

Being able to define nested forms would be awesome. If you had a object with relationships, which has relationships. You could define a form within a form within a form.

markst avatar Dec 18 '14 02:12 markst

You can already make forms within forms - just define one of your root form's fields as being another FXForm object (the example app does this). The OP had a slightly different requirement.

nicklockwood avatar Aug 31 '16 08:08 nicklockwood