Hello, everyone, I need help with Xamarin
I now that Xamarin forums are moving here
I am making basic validation forms with an email, and password, but it doesn't work correctly. If I enter a name and I enter a valid email, it says "name cannot be empty"
namespace ValidateFormularies.ViewModels {
class ValidatorVM : ViewModelBase {
private string _name;
public string name {
get { return _name; }
set {
if (_name != value) {
_name = value;
Validate(name);
RaisePropertyChanged();
}
}
}
private string _email;
public string email {
get { return _email; }
set {
if (_email != value) {
_email = value;
Validate(email);
RaisePropertyChanged();
}
}
}
private bool _isVisible;
public bool isVisible {
get { return _isVisible; }
set {
if (_isVisible != value) {
_isVisible = value;
RaisePropertyChanged();
}
}
}
private string _msg;
public string msg {
get { return _msg; }
set {
if (_msg != value) {
_msg = value;
RaisePropertyChanged();
}
}
}
private void Validate(string prop) {
if (prop.Equals(email)) {
if (!EmailValidator.IsValidEmail(email)) {
isVisible = true;
msg = "Email needs to be valid";
} else if (string.IsNullOrEmpty(email)) {
msg = "Email cannot be empty";
} else {
isVisible = false;
}
} else if (prop.Equals(name)) {
if (string.IsNullOrEmpty(name)) {
isVisible = true;
msg = "name cannot be empty";
} else {
isVisible = false;
}
}
}
}
}
Actually, this works, but not quite as expected
For example, If I enter my name in a random email, it will tell name cannot be empty
Also, can you explain why would you use nameOF?
my view
<StackLayout>
<Entry Placeholder="Name" Text="{Binding name, Mode=TwoWay}" />
<Label Text="{Binding msg, Mode=TwoWay}"
IsVisible="{Binding isVisible, Mode=TwoWay}"
TextColor="Red" />
<Entry Placeholder="Email" Text="{Binding email, Mode=TwoWay}" />
<Label Text="{Binding msg, Mode=TwoWay}"
TextColor="Red"
IsVisible="{Binding isVisible, Mode=TwoWay}" />
</StackLayout>
I updated my code a bit