Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with EZFormRadioField with array updated dinamically based on value in another fiels #44

Open
appfabtech opened this issue Jan 29, 2014 · 4 comments

Comments

@appfabtech
Copy link

Hello

I'm trying to implement a EZFormRadioField with UIPickerView with setChoicesFromArray called dinalically based on other field value.

I check the values changing in

  • (void)form:(EZForm *)form didUpdateValueForField:(EZFormField *)formField modelIsValid:(BOOL)isValid
    {
    if ([formField.key isEqualToString:@"country"]) {
    [self updateRegionCountry];
    }

}

and in updateRegionCountry I update the EZFormRadioField content with a new array passed with setChoicesFromArray.
Everything work but when I open the picker I have the new values but the number of items shown are limited to previous array count.

I mean if first array assigned with setChoicesFromArray had 20 elements, and the new array has 30 elements, the Picker shows the new elements but only the first 20.
Please note that both choices and orderedKeys in EZFormRadioField have the right number of elements after the update, but the picker still shows only 20 elements

@amcastror
Copy link

Hi, were you able to solve this? Thanks.

@appfabtech
Copy link
Author

Hi
I found a fix, calling setChoicesFromKeys before the Picker allocation and just after it
[stateField setChoicesFromKeys:[state valueForKey:@"value"] values:[state valueForKey:@"label"]];
stateField.inputView = [[UIPickerView alloc] initWithFrame:CGRectZero];
[stateField setChoicesFromKeys:[state valueForKey:@"value"] values:[state valueForKey:@"label"]];

Now it works like a charm

@amcastror
Copy link

Thanks for the answer.. With a little more work I was able to solve it a little different. I only use the second setChoices method:

EZFormRadioField *subTypeField = [form formFieldForKey:REPORT_KEY_SUB_TYPE];

[subTypeField setChoicesFromArray:[NSArray arrayWithArray:sub_types]];
[subTypeField setValidationRequiresSelection:YES];
[subTypeField setValidationRestrictedToChoiceValues:YES];
[subTypeField setUnselected:@"Choose"];
[subTypeField setFieldValue:nil];

[(UIPickerView *)subTypeField.inputView reloadAllComponents];
[(UIPickerView *)subTypeField.inputView selectRow:0 inComponent:0 animated:YES];

Works like a charm too. Cheers.

@jessedc
Copy link
Contributor

jessedc commented Feb 7, 2014

Hey guys, I've been following along from a distance - are there any additions we could make to EZForm to support this kind of functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants