Maui.FreakyControls icon indicating copy to clipboard operation
Maui.FreakyControls copied to clipboard

FreakyTextInputLayout with maui toolkit validation

Open SalvatoreDiFede opened this issue 1 year ago • 3 comments

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!

SalvatoreDiFede avatar Apr 18 '24 10:04 SalvatoreDiFede

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...

FreakyAli avatar Apr 18 '24 19:04 FreakyAli

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 :(

SalvatoreDiFede avatar Apr 18 '24 19:04 SalvatoreDiFede

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 avatar Apr 19 '24 12:04 FreakyAli

@SalvatoreDiFede Did you get anywhere with this?

FreakyAli avatar May 09 '24 11:05 FreakyAli

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

FreakyAli avatar May 15 '24 21:05 FreakyAli

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

SalvatoreDiFede avatar May 16 '24 07:05 SalvatoreDiFede