nicklockwood / FXForms

[DEPRECATED]
Other
2.93k stars 339 forks source link

Update Field Value and refresh display after selecting from options #431

Closed jatindhawan closed 8 years ago

jatindhawan commented 8 years ago

I have a CreateFormViewController, init looks like below:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
    {
        //set up form
        self.myForm = [[DynamicForm alloc] init];
        self.formController.form = self.myForm;
        self.formController.tableView = self.tableView;
    }
    return self;
}

I am first using a json file to define all fields. Consider this example of a field which has following properties:

@{FXFormFieldKey: @"Reason" , FXFormFieldTitle: [transLib valueForKey:@"Reason"] , FXFormFieldOptions: @[ @"test"], FXFormFieldHeader: @"Appointment Details",FXFormFieldType: @"Text"}

Now in the Dynamicform I have assigned a customised FXFormFieldViewController to Reason field:

- (NSDictionary *)ReasonField
{
    return @{FXFormFieldViewController: @"FieldSelectorViewController"};
}

Now in FieldSelectorViewController, I get data from server and display all options and then upon selection of a field I tried a few things to update the field value in the form from previous controller:

  1. I have tried sending a NSNotification with data and then simply calling the below:
[self.myForm setValue:displayValue forKey:keyName];
self.formController.form = self.myForm;
[self.tableView reloadData];
  1. FieldSelectorViewController also has a field property, I have tried updating that field's value
  2. I have also tried the below on the callback after selection: [self.formController enumerateFieldsWithBlock:^(FXFormField field, NSIndexPath indexPath) { if ([field.key isEqualToString:keyName]) { field.value = displayValue; [self.tableView reloadData]; } }];

but it is not working

jatindhawan commented 8 years ago

@nicklockwood Do you know what I'm trying to ask, need more details?

nicklockwood commented 8 years ago

The FieldSelectorViewController should have a field property of type FXFormField, like this:

@property (nonatomic, strong) FXFormField *field;

This will be automatically populated by the parent form (your DynamicForm class) when the Reason field is selected.

To update the value from within the FieldSelectorViewController, just set the value of the field, like this:

self.field.value = @"New Value";

And that should then update the value of the Reason property in the DynamicForm. To refresh the display of the field in the FieldSelectorViewController you may also need to call

[self.tableView reloadData];
jatindhawan commented 8 years ago

Yes thats what I am doing, don't know why isnt it working

Sent from my iPhone

On Dec 2, 2015, at 9:21 PM, Nick Lockwood notifications@github.com<mailto:notifications@github.com> wrote:

The FieldSelectorViewController should have a field property of type FXFormField, like this:

@property (nonatomic, strong) FXFormField *field;

This will be automatically populated by the parent form (your DynamicForm class) when the Reason field is selected.

To update the value from within the FieldSelectorViewController, just set the value of the field, like this:

self.field.value = @"New Value";

And that should then update the value of the Reason property in the DynamicForm. To refresh the display of the field in the FieldSelectorViewController you may also need to call

[self.tableView reloadData];

Reply to this email directly or view it on GitHubhttps://github.com/nicklockwood/FXForms/issues/431#issuecomment-161496123.

nicklockwood commented 8 years ago

I think I'm going to have to see more of the code to debug this.

jatindhawan commented 8 years ago

found the problem, I was supplying options through property FXFormFieldOptions: @[ @"test"] and that coupled with FXFormFieldViewController: @"FieldSelectorViewController"

presence of both of these was preventing the update of value as I guess it must have been looking for a value from one of the options.