chrismiles / EZForm

iOS form handling and validation library.
MIT License
284 stars 64 forks source link

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

Open appfabtech opened 10 years ago

appfabtech commented 10 years ago

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

}

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 commented 10 years ago

Hi, were you able to solve this? Thanks.

appfabtech commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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?