reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Clear default value

Open SaddamMohsen opened this issue 2 years ago • 5 comments

Hi, I have a FormControl with default value 0 like this

'prodTray': FormControl<int>(
      value: 0,
      validators: [Validators.number, Validators.pattern(kTrayNumberPattern)],
    ),

so i want when the user Tap on this field clear the dafault value and empty the field

How can i do this Thank in advance

SaddamMohsen avatar Jul 19 '23 18:07 SaddamMohsen

Thank you i found the solution onTap:(FormControl<int> control)=>control.value=null,

i will close the issue

SaddamMohsen avatar Jul 19 '23 18:07 SaddamMohsen

Hi @SaddamMohsen

You can also use just

control.reset()

joanpablo avatar Jul 19 '23 19:07 joanpablo

Hi @SaddamMohsen

You can also use just

control.reset()

thank you very much this what i want

SaddamMohsen avatar Jul 19 '23 19:07 SaddamMohsen

Thank you @joanpablo i have another question how can i using reactive form with stepper widget

SaddamMohsen avatar Jul 19 '23 19:07 SaddamMohsen

Hi @SaddamMohsen,

Any situation is different. Here are two common patterns:

1- Having just one FormGroup and binding widgets of each step to the controls in the group.

  • This is for simple scenarios, you basically split a simple form into several views.
  • Each step almost always has one up to three reactive widgets controls.
  • You validate the Form at the end but you can always restrict when to jump into the next step based on the validity of an individual control of the active view.

1- Having a parent FormGroup with several nested FormGroup.

  • This is for more complex Forms.
  • You will have a FormGroup for each step. Usually in each step, you have more than three widgets, and complex business validations.
  • Even though you validate the entire flow (all the steps) at the end with the parent FormGroup, you have more strict control and validation on each step.

I hope this can help you understand when to use what variation.

joanpablo avatar Aug 13 '23 19:08 joanpablo