Reputation: 439
I'm trying to implement validation within my Xamarin Forms application and I've followed the following example:
This works fine within my project. When a numeric value is not entered, the Entry control will display in red to the user.
But i'm wondering the best practice for stopping the user submitting information to the web service if the validation fails? I can code for this, but wondering best practice or a built in way to do this, similar to Microsoft MVC with Webforms.
I've seen a few examples where validation displays the error, but not stopping the call to the web service.For example, if a date entry has not been entered.
Let me know if you want some code, but the example link is more or less what I've done.
Thanks
Upvotes: 0
Views: 779
Reputation: 12179
Well, the problem you described is relatively simple. Can be solved in different ways.
Here is one way you could try to adapt:
Your ViewModel
which represent the data to be sent to the API should have a property like IsValid
, that will represent the validity of the whole object. This property should be bound than to Command.CanExecute
, to disable the button that send the data to the API. So if IsValid
will be false the send button will be also disabled.
Upvotes: 1