form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

Keep values on UpdateFieldBlocItems

Open sm2017 opened this issue 5 years ago • 2 comments

Here https://github.com/GiancarloCode/form_bloc/blob/master/packages/form_bloc/lib/src/blocs/multi_select_field/multi_select_field_bloc.dart#L158

Once we update items items.contains(value) is always false because value is a List and when we update items, value set to Optional.of([]) and we loose selected values

sm2017 avatar Jul 20 '20 10:07 sm2017

Thanks, yes, you're right, it's a mistake.

I'm still not sure which is the best solution, could you give your opinion please.

  1. Remove all items from the list
  2. Preserve the items on the list only if they are all in the new item list.
  3. Preserve only the items that are in the new item list.

Maybe I can also add an optional parameter, for more control.


And related to this, should we allow the multi select field bloc and the select field bloc to be assigned an element that is not included in the item list?

GiancarloCode avatar Jul 20 '20 16:07 GiancarloCode

@GiancarloCode I think the best way is an optional enum parameter , When we call updateItems all old items removed and new items added ,The problem is selected values

enum OnUpdateItems{ 
   remove, // Remove all selected values
   keep, // Keep all selected values, no matter values exists in new items or not (I have use case)
   keepOnlyExists, // Keep all selected values that exists in new items and remove others
}

And related to this, should we allow the multi select field bloc and the select field bloc to be assigned an element that is not included in the item list?

I think absolutely YES! , I have use case for this , in my current app, I have an infinitive tags, it is not possible to add all tags in items, but user can search in in a type ahead field, it is too cumbersome to manage both items and values for developers

sm2017 avatar Jul 21 '20 06:07 sm2017