nicklockwood / FXForms

[DEPRECATED]
Other
2.93k stars 339 forks source link

Option select multiple but not twice the same #311

Open iNono22 opened 9 years ago

iNono22 commented 9 years ago

Hi, I'm trying to manage something. I have an NSArray, people can choose multiple categories option. But when he select one, I don't him to have the possibility to select the same again, so I want to remove the previous selected categories.

- (NSDictionary *)categoriesField {
    NSArray *arrayCat = @[@"Football", @"Tennis", @"Golf", @"BasketBall", @"Powerbocking"];

    return @{ FXFormFieldInline: @YES,
              FXFormFieldTemplate: @{
                      FXFormFieldOptions: arrayCat
                      }
              };
}

Can you help?

iNono22 commented 9 years ago

And one more thing I try to manage is: If he press on "add item cell" he has to select a category before being able to tap again on "add item cell" avoid

iNono22 commented 9 years ago

For those who search the same answer for my first question:

- (NSDictionary *)categoriesField {
    NSMutableArray *arrayCat = [@[@"Football", @"Tennis", @"Golf", @"BasketBall", @"Powerbocking"] mutableCopy];
    [arrayCat removeObjectsInArray:self.categories];
    return @{ FXFormFieldInline: @YES,
              FXFormFieldAction: @"updateFields",
              FXFormFieldTemplate: @{
                      FXFormFieldOptions: arrayCat
                      }
              };
}
- (void)updateFields {
    //refresh the form
    self.formController.form = self.formController.form;
    [self.tableView reloadData];
}