FreakyAli / Maui.FreakyControls

FreakyControls is a free OSS UI Kit for .NET MAUI which provides a set of controls and utilities to build modern mobile apps.
MIT License
294 stars 36 forks source link

FreakyTextInputLayout with maui toolkit validation #115

Closed SalvatoreDiFede closed 4 months ago

SalvatoreDiFede commented 5 months ago

Hi there, it would be nice to implements behaviors for Entry from communitytoolkit

For example: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/text-validation-behavior

Problem: FreakyTextInputLayout derives from ContentView and FreakyEntry is not binded, nor public.

Any idea on how to solve or implement this?

Thank'u!

FreakyAli commented 5 months ago

Well I don't know if there is a direct way to do this, but what you could do is recreate your version of this Validator the original code which can be found here: https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui/Behaviors/Validators/TextValidationBehavior.shared.cs

And, you could add some code to this behaviour that gets the Entry reference through FindByName and then apply the behaviour accordingly, Name for the View is here: https://github.com/FreakyAli/Maui.FreakyControls/blob/0de0401657edb3247c0e226a60ab577c05a5c504/MAUI.FreakyControls/MAUI.FreakyControls/Shared/FreakyTextInputLayout/FreakyTextInputLayout.xaml#L24

So in the OnAttach method you would do something like this:

public class TextValidationBehavior : Behavior<FreakyTextInputLayout>
    {
        protected override void OnAttachedTo(FreakyTextInputLayout bindable)
        {
            base.OnAttachedTo(bindable);
            var entry = bindable.FindByName("EntryField");
        }
    }

There is also a BehvaviorBase implementation in FreakyControls that you can use to get the AssociatedObject without creating a reference for it manually: https://github.com/FreakyAli/Maui.FreakyControls/blob/master/MAUI.FreakyControls/MAUI.FreakyControls/Shared/Behaviors/BehaviorBase.cs

Hope this makes sense,

Feel free to ask any questions that come to mind...

SalvatoreDiFede commented 5 months ago

Oh, thanks, i'll try!

BTW my original idea was to set EntryField public and bindable and to add something like this:

[TypeConverter(typeof(Field))] public Field EntryField { get { return (Field)GetValue(EntryFieldProperty); } set { SetValue(EntryFieldProperty, value); } }

I apologize but my knowledge of this is very limited :(

FreakyAli commented 5 months ago

It's fine, do let me know if you face any issues, and I will try to help you out, how much ever i can!

FreakyAli commented 4 months ago

@SalvatoreDiFede Did you get anywhere with this?

FreakyAli commented 4 months ago

@SalvatoreDiFede I will close this assuming you worked things out, you can always reopen this or create a new one if needed!

SalvatoreDiFede commented 4 months ago

Thank'u @FreakyAli . Had no way nor time to implement this lately. Sorry