Stacked-Org / stacked

A Flutter application architecture created from real world scenarios
MIT License
957 stars 255 forks source link

[feature]: FormTextField validator function various data types such as numbers #1074

Closed 0001arunsharma closed 8 months ago

0001arunsharma commented 9 months ago

Is your feature request related to a problem? Please describe.

I find it somewhat challenging when dealing with the FormTextField validator function as it exclusively accepts strings, which can make the process a bit laborious.

Describe the solution you would like

would be appreciated it if the solution could encompass support for various data types such as numbers, in addition to strings.

Additional Context

FormTextField FormTextField({ String? name, String? initialValue, String? Function(String?)? validator, dynamic Function()? customTextEditingController, })

ferrarafer commented 8 months ago

Hi @0001arunsharma , I think there is no need for this feature. The value is passed as a nullable String but in the function you can treat it as a number. For example, see on the documentation how we don't allow numbers on a input field using regex. An alternative could be to cast the value to a number and do the validation needed.

FilledStacks commented 8 months ago

Did this work @0001arunsharma

0001arunsharma commented 8 months ago

@ferrarafer @FilledStacks Apologizes for late response. The documentation is clear to us but we are asking user to enter the price of product and we are validating the user input. So we thought instead of casting string as a number if we can define the parameters type in validator function will me more straight forward. As a workaround we can cast value as a number and doing the validation. Thanks

FilledStacks commented 8 months ago

I see, since text can take anything it'll always be string. We could probably build a cast -> type generic style middleware for the validator, but that would be more work than doing the cast in the validator as it's needed.

Thanks for the response.