reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

in ReactiveTextField widget set initial value as control(TextEditingController) value

Open Imesh7 opened this issue 3 years ago • 4 comments

@joanpablo I needs to set initial value of TextEditingController()..text value, How to overcome this situation

ReactiveTextField<String>(
                  formControlName:"control",
                  controller: TextEditingController()..text = value.name ?? '',
                  textInputAction: TextInputAction.next,
                  keyboardType: TextInputType.name,
                  textAlign: TextAlign.start,
                  decoration: const InputDecoration(
                    prefixIcon: Icon(Icons.account_circle_outlined),
                  ),
                ),

Imesh7 avatar Feb 10 '23 11:02 Imesh7

You need to set you value in control and it will be automatically supplied to controller https://github.com/joanpablo/reactive_forms/blob/master/lib/src/widgets/reactive_text_field.dart#L278

final form = FormGroup({
  'control': FormControl<String>(value: 'John Doe'),
});

vasilich6107 avatar Feb 10 '23 18:02 vasilich6107

You need to set you value in control and it will be automatically supplied to controller https://github.com/joanpablo/reactive_forms/blob/master/lib/src/widgets/reactive_text_field.dart#L278

final form = FormGroup({
  'control': FormControl<String>(value: 'John Doe'),
});

@vasilich6107 In the ReactiveTextField widget parameter called FormControl<ModelDataType>? formControl , I needs to set the initial value to it. I have tried to do, its not working for me. Is there any ways to do this?

Imesh7 avatar Feb 13 '23 05:02 Imesh7

@vasilich6107 have you understood my question

Imesh7 avatar Mar 01 '23 13:03 Imesh7

Hi @Imesh7,

Is there any reason why you don't want to set the initial value to the FormControl like

'control': FormControl<String>(value: 'John Doe'),

Just as @vasilich6107 suggested to you?

joanpablo avatar Mar 01 '23 14:03 joanpablo