flutter_form_builder icon indicating copy to clipboard operation
flutter_form_builder copied to clipboard

[FormBuilderChoiceChips] Add property isChoiceRequired

Open Artur110 opened this issue 5 years ago • 2 comments

Can you please add isChoiceRequired bool (or sth like that) to FormBuilderChoiceChips widget? It is helpful if developer has to make choice chips like switcher between multiple choices. If isChoiceRequired == true, then initial value should be provided, or, if it's not, first choice should be chosen as initial.

Inside FormBuilderChoiceChips widget: ... final bool isRequiredChoice; ... this.isRequiredChoice = false, // set it to false as default in constructor ...

Inside build() method in ChoiceChip's onSelected handler:

final choice = selected ? option.value : widget.isRequiredChoice ? field.value : null;

P.S. I've made fork for this thing and it works fine, but I got tired updating it 😅

Artur110 avatar Dec 04 '20 13:12 Artur110

Why don't you just set the initialValue so that it is not null, and combine that with a Required validator?

awhitford avatar Dec 05 '20 10:12 awhitford

Why don't you just set the initialValue so that it is not null, and combine that with a Required validator?

Because it expands UI with error message and makes possible UI without any selected choice. As I said, this parameter (isRequiredChoice) would be helpful to create choice chips with one required choice (with default value) and without any error messages.

Artur110 avatar Dec 07 '20 11:12 Artur110