flutter_form_builder icon indicating copy to clipboard operation
flutter_form_builder copied to clipboard

[FormBuilderCheckboxGroup] patchValue don't work

Open Iccr opened this issue 4 years ago • 4 comments

I am trying to set values with patchvalue like this.

var state = searchModel.value.formKeys.formKey.currentState;

      state.patchValue({
        "map_field": searchModel.value.address ?? "",
        "noOfROoms": searchModel.value.noOfRoom,
        "price_upper": searchModel.value.priceUpper,
        "price_lower": searchModel.value.priceLower,
        "Type": searchModel.value.type,
        "water": searchModel.value.water,
        "parking": searchModel.value.parkings,
      });

parking is a FormBuilderCheckboxGroup<Parking> and the searchModel.value.parkings is of type List<Parking>

everything except "parking" is displaying correct values. Parking widget should have checked state for those values. But it is not showing those selected states. didChange(val) does not seems to get the desired result. state.fields['parking'].didChange(searchModel.value.parkings);

But then, when I print the value, state.fields['parking'].value after patching. This is giving the correct values. Also onChange in the widget is getting called with the correct given values. I gues that means values are been set. But the check box is not selected as it should have been. However If I give the same value as initialValue, check box are selected as expected. Am I doing anything wrong here?

Iccr avatar Feb 27 '21 06:02 Iccr

UI is not being updated I think. I have similar issue and found no workaround to it.

harlanx avatar Feb 28 '21 12:02 harlanx

I am using this in production. I got no option but to hide this feature since I cannot find any workaround. @danvick Is there any work around for this.

Iccr avatar Mar 04 '21 02:03 Iccr

I was trying to patch values when initializing the page and ran into the same problem. I solved this by conditionally setting the initial value and now the UI is displaying correctly. Maybe you could try my solution and call setState to rebuild the UI.

piyachetk avatar May 11 '21 13:05 piyachetk

This still a issue with the lasted version?

deandreamatias avatar Jul 21 '22 08:07 deandreamatias

Due to lack of response and an old error, I will close this issue. If the bug still exists, feel free to open a new issue

deandreamatias avatar Sep 17 '22 16:09 deandreamatias