artflutter / reactive_forms_generator

Other
89 stars 22 forks source link

Avoid calling `model` on invalid form message on Disable form #140

Closed airychkov closed 9 months ago

airychkov commented 9 months ago

add if (!currentForm.valid && if (!currentForm.disbaled) {) {

to if (!currentForm.valid) { debugPrint('[\${path ?? '$classNameFull'}]\n┗━ Avoid calling model on invalid form. Possible exceptions for non-nullable fields which should be guarded by required validator.'); }

vasilich6107 commented 9 months ago

hi. could you explain the reason on adding this additional check?

airychkov commented 9 months ago

Hi! I have part of form as FormGroup disabled by default. Data in disabled part is valid (but it's not matter) User can activate FormGroup by switch if needed Main Form -> FormGroup with switch -> Sub FormGroup with data and validators By default disabled part of From is invalid. I think if part form is disabled no need to check valid and show message.

I hope I can explain

vasilich6107 commented 9 months ago

If you have

required SomeType type

variable in your model - the calling of model on invalid form could cause the crash off the app cause nullish value from form will be casted to non nullable type. This is why the warning was added.

So it will be better to check your form and validators rather than silencing the possible issue warning.

airychkov commented 9 months ago

Maybe I don't something. In debug I see: no errors and form valid = false and invalid = false And form is valid with default values. I

See attachment

Снимок экрана 2023-12-12 в 19 10 31
vasilich6107 commented 9 months ago

@airychkov it seems that disabled forms are not valid. I do not why You can clarify here https://github.com/joanpablo/reactive_forms

vasilich6107 commented 9 months ago

@airychkov this issue has more information https://github.com/joanpablo/reactive_forms/issues/172

anyway, the form behavior is out of scope for this library so I'm closing the issue

github-actions[bot] commented 9 months ago

Hi @airychkov! Your issue has been closed. If we were helpful don't forget to star the repo.

Please check our reactive_forms_widget package

We would appreciate sponsorship subscription or one time donation https://github.com/sponsors/artflutter

vasilich6107 commented 6 months ago

Hey @airychkov check https://pub.dev/packages/reactive_forms_generator/versions/4.6.0-beta.1

I updated the if logic so it should spam less.

airychkov commented 6 months ago

Hello! That's better! no extra logs Thank you

airychkov commented 6 months ago

By the way I made few components for my project: CupertinoPicker, flutter_xlider. I can share it.

vasilich6107 commented 6 months ago

Would be a nice addition Could you share them in some way so I can include into the packages

airychkov commented 6 months ago

rf_comonents.zip components in attachment, if you want I can make it better.