Reset fields' value (use value of initialFields to replace current value of $) & call method reset of each field.
class FormState {
private initialFields
constructor(initialFields) {
// we should do shallow clone here in case of fields' in-place modification
this.initialFields = shallowClone(initialFields)
}
reset() {
// reset fields' value
this.$ = this.initialFields
// reset each field's value
this.fields.forEach(
field => field.reset()
)
}
}
It may be more reasonable to do real reset in
FormState
instance methodreset
.Current behavior
Call method
reset
of each field:https://github.com/qiniu/formstate-x/blob/f6a3e3ed6835a6560d389298621d8a9429c3916f/src/formState.ts#L174-L176
Expected behavior
Reset fields' value (use value of
initialFields
to replace current value of$
) & call methodreset
of each field.