question

ffrige-4934 avatar image
0 Votes"
ffrige-4934 asked JessieZhang-2116 commented

Entry.ReturnCommand skipped when keyboard loses focus

I use an Entry control to edit a text and then I execute the ReturnCommand to check and modify its content. That all worked fine until I found out that when the users taps away from the input keyboard the text is saved but the ReturnCommand is not executed.

It seems there are no other commands that can be triggered when the Entry is completed. Is there a solution to that?

I cannot use the set property of the variable in the binding because that would modify the text while the user is typing, which makes a big mess.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered

Hello,


Welcome to our Microsoft Q&A platform!

That all worked fine until I found out that when the users taps away from the input keyboard the text is saved but the ReturnCommand is not executed.

When we check document Customize the return key, we will find that :

The appearance of the return key on the soft keyboard, which is displayed when an Entry has focus, can be customized by setting the ReturnType property to a value of the ReturnType enumeration:

  • Default – indicates that no specific return key is required and that the platform default will be used.

  • Done – indicates a "Done" return key.

  • Go – indicates a "Go" return key.

  • Next – indicates a "Next" return key.

  • Search – indicates a "Search" return key.

  • Send – indicates a "Send" return key.

And when the return key is pressed, the Completed event fires and any ICommand specified by the ReturnCommand property is executed.

So, the ReturnCommand is triggered only when the return key on the soft keyboard is clicked. That's why when you taps away from the input keyboard, the event didn't fire.

I cannot use the set property of the variable in the binding because that would modify the text while the user is typing, which makes a big mess.

For this ,we usually set property of the variable in the binding to achieve this funtion just as you mendtioned.
For more details, you can refer to the official document: The Xamarin.Forms Command Interface .

In addition, what do you mean by words a big mess? Can you explain it in detail?


Best Regards,

Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ffrige-4934 avatar image
0 Votes"
ffrige-4934 answered JessieZhang-2116 commented

Hello Jessie,

Thank you for your answer. What I meant to say is that in certain cases it is not convenient to check and modify the text while the user is still typing. It would be much better to have a way to wait until the end, i.e. when the return key is pressed or when the keyboard loses focus.

To give you a practical example: I have entries for user IDs. Each user can enter an ID, which is accepted only if no other user has entered the same value before. When checking that at the end of the entry process I can reset the value to zero and explain the reason with a pop-up message. However, if I have to check that while the user is typing it gets messy. Imagine for instance that one user already entered the ID "1". Now another user wants to have the ID "15", which is totally valid. But as soon as he starts typing the first digit "1" the value gets deleted and an error pops up saying that the ID "1" has already been taken.

I think the cleanest solution would be either to allow the keyboard to disappear only if the return key is pressed (and not by just tapping away from it), or to always trigger the return key whenever the keyboard closes (no matter what the reason was for it to close).

I hope you understand what I mean.
Thank you very much for your help!
Fabrizio

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can check the validity of the input value util you have entered the whole value for a entry. Have you tried event TextChanged ?


0 Votes 0 ·