Open yeikel16 opened 9 months ago
Hi @yeikel16 Thanks for the PR. I would like to know your opinion about the following question:
Given this code:
const pureValue = 'pureValue';
// A control with some default value
final control = FormControl<String>(
value: pureValue,
touched: true,
);
// Change the initial value in the control
control.value = 'new value';
What would be the benefit of:
control.reset()
over the current implementation:
control.reset(value: pureValue)
Given this code:
const pureValue = 'pureValue'; // A control with some default value final control = FormControl<String>( value: pureValue, touched: true, ); // Change the initial value in the control control.value = 'new value';
What would be the benefit of:
control.reset()
over the current implementation:
control.reset(value: pureValue)
Hello @joanpablo, right now you need to pass the value when resetting the control, forcing it to have the value to be assigned in the reset()
function at all times. On the other hand, if nothing is passed, the value of the control remains null, being a bit confusing for the function that it must fulfill according to the name of said reset()
function, for this last case I would recommend including a more specific function and descriptive like clean()
.
With this PR, simply calling the reset()
function will take the value with which the control was created and restart it without extra work.
Hi @yeikel16,
Thanks for the quick response. You are right, I fully understand now the benefits. I agree 100% with you. I would need some time to review this PR thoroughly. It is an important feature and your PR is making important changes in the core of Reactive Forms.
Thanks once again for the contribution and for the patience
Hey @joanpablo any chance for this to be reviewd?
Connection with issue(s)
Close #436
Connected to #382
Solution description
Right now the
reset
method allow set to null the value of the control, but could not apply to change the initial value of the control when is called. This PR allows you to discard changes made to the form fields. In some forms it is necessary to update values initially provided, and in some cases it is necessary to reset them with the initial values, for example a user profile where you need to update your personal data.Screenshots or Videos
To Do