-
Notifications
You must be signed in to change notification settings - Fork 370
Description
Description
I am performing it on Net Maui, Mac and iOS, they fail, on Android it usually works. On windows I did not test it.
I will copy the code so you can reproduce it.
I enter the first name, then the last name, but I add one letter less to the first name so that it does not meet the validation rule, then I add the correct, ie, one more letter to name, so the validation is correct, but the button no longer works. And if I use the version with CanShow, it does not update its status on the screen, it does not react to changes in the number of letters, but internally it is detected and writes the message according to the result. It is easier to reproduce it than to explain it. You can see that the button with the text try Save Valida Command does not work the second time, when everything is valid, if I close and open the program it works but only the first time.
Reproduction Sample file UI
public class MainPageCSharpMarkupValidationfluentDI : ContentPage
{
int count = 0;
readonly vmPersona _vm;
public MainPageCSharpMarkupValidationfluentDI(vmPersona vm)
{
BindingContext = _vm = vm;
var mi_scrollView = new ScrollView();
var mi_verticalStacklayout = new VerticalStackLayout
{
Spacing = 25,
Children =
{
new Label
{
Text="Validacion C# Markpu DI!",
}
.Font(size: 32).CenterHorizontal(),
new Label().Bind(Label.TextProperty, nameof(vm.Mensaje)),
new Label().Bind(Label.TextProperty, (nameof(vm.CanShow)).ToString()),
new Button()
.Text("ver si esta forma anda")
.BindCommand(nameof(vm.ShowCommand))
.CenterHorizontal(),
new Entry()
{
Keyboard = Keyboard.Chat,
BackgroundColor = Colors.AliceBlue,
}.FontSize(15)
.Placeholder("Enter name")
.TextColor(Colors.Black)
.Height(44)
.Margin(5, 5)
.Bind(Entry.TextProperty, nameof(vm.Nombre)),
new Label().Bind(Label.TextProperty, nameof(vm.Nombre)),
new HorizontalStackLayout
{
Children=
{
new VerticalStackLayout
{
Children=
{
new Label {Text="First Name"},
new Entry().FontSize(15)
.Placeholder("First Name")
.TextColor(Colors.Black)
.Height(44)
.Margin(5, 5)
.Width(300)
.Bind(Entry.TextProperty, nameof(vm.FirstName)),
new Label().Bind(Label.TextProperty, nameof(vm.FirstName)),
}
},
new VerticalStackLayout
{
Children=
{
new Label {Text="Last Name"},
new Entry()
.FontSize(15)
.Placeholder("last Name")
.TextColor(Colors.Black)
.Height(44)
.Margin(5, 5)
.Width(300)
.Bind(Entry.TextProperty, nameof(vm.LastName)),
new Label().Bind(Label.TextProperty, nameof(vm.LastName)),
}
}
}
}.CenterHorizontal(),
new VerticalStackLayout
{
Children=
{
new Button()
.Text("try Save Valida Command")
.BindCommand(nameof(vm.SaveValidaCommand))
.CenterHorizontal()
}
},
new Label().Bind(Label.TextProperty, nameof(vm.FullName)),
new Label().Bind(Label.TextProperty, nameof(vm.FullNameValida)),
new Label{Text="Ver respuesta de Validación Fluent ....."}
.Font(size: 24, bold:true).CenterHorizontal(),
new Label{Text="ErrorMensajePasa", TextColor=Colors.BlueViolet},
new Label().Bind(Label.TextProperty, nameof(vm.ErrorMensajePasa)),
new Label{Text="ErrorMensajeGeneral", TextColor=Colors.BlueViolet},
new Label().Bind(Label.TextProperty, nameof(vm.ErrorMensajeGeneral)),
new Label{Text="FirtNameError", TextColor=Colors.BlueViolet},
new Label().Bind(Label.TextProperty, nameof(vm.FirtNameError)),
new Label{Text="LastNameError", TextColor=Colors.BlueViolet},
new Label().Bind(Label.TextProperty, nameof(vm.LastNameError)),
new Label{Text="Fin respuesta Validación, inicio para ver si anda el mvvm ..."}
.Font(size: 24, bold:true).CenterHorizontal(),
new Button()
.Text("Valida Excecute SingUpCommand")
.Font(bold: true)
.BindCommand(nameof(vm.ExecuteSignUpCommand))
.CenterHorizontal(),
}
}.Paddings(30, 30, 30, 30);
mi_scrollView.Content = mi_verticalStacklayout;
Content = mi_scrollView;
}
}
Reproduction Sample file FluentValidation
public class vPersona : AbstractValidator
{
public vPersona()
{
RuleFor(x => x.Name).NotNull().Length(5, 20).NotEqual("Javier");
RuleFor(x => x.Surname).NotNull().Length(4, 20);
}
}
public class mPersona
{
public string Name { get; set; }
public string Surname { get; set; }
}
Reproduction Sample file mvvm
public partial class vmPersona : ObservableObject
{
public mPersona PersonaObj { get; set; }
private readonly vPersona _validator;
public vmPersona()
{
_validator = new vPersona();
}
[ObservableProperty]
// [AlsoNotifyChangeFor(nameof(ExecuteSignUpCommand))]
[NotifyCanExecuteChangedFor(nameof(ExecuteSignUpCommand))]
// [AlsoNotifyChangeFor(nameof(MensajeValidaNombre))]
string nombre;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
// [AlsoNotifyChangeFor(nameof(FullName))]
// [NotifyCanExecuteChangedFor(nameof(validaNuevoJavier))]
[NotifyCanExecuteChangedFor(nameof(ShowCommand))]
private string firstName = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullName))]
//[AlsoNotifyChangeFor(nameof(FullName))]
// [NotifyPropertyChangedFor(nameof(validaNuevoJavier))]
[NotifyCanExecuteChangedFor(nameof(ShowCommand))]
private string lastName = string.Empty;
public string FullName => $"{FirstName} {LastName}";
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullNameValida))]
//[AlsoNotifyChangeFor(nameof(FullNameValida))]
[NotifyCanExecuteChangedFor(nameof(SaveValidaCommand))]
// [NotifyCanExecuteChangedFor(nameof(validaNuevoJavier))]
private string firstNameValida = string.Empty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(FullNameValida))]
// [AlsoNotifyChangeFor(nameof(FullNameValida))]
[NotifyCanExecuteChangedFor(nameof(SaveValidaCommand))]
// [NotifyPropertyChangedFor(nameof(validaNuevoJavier))]
private string lastNameValida = string.Empty;
public string FullNameValida => $"{FirstNameValida} {LastNameValida}";
[RelayCommand(CanExecute = nameof(CanSaveExecute), IncludeCancelCommand = true)]
// [ICommand(CanExecute = nameof(CanSaveExecute), IncludeCancelCommand = true)]
private async Task SaveValidaAsync(CancellationToken cancelToken)
{
// Code to save the user details .... CanSaveExecute
await Task.FromResult(0);
}
private bool CanSaveExecute()
=> !string.IsNullOrWhiteSpace(FirstName) && !string.IsNullOrWhiteSpace(LastName);
[ObservableProperty]
string errorMensajePasa = string.Empty;
[ObservableProperty]
string errorMensajeGeneral = string.Empty;
[ObservableProperty]
string firtNameError = string.Empty;
[ObservableProperty]
string lastNameError = string.Empty;
// [ICommand]
[RelayCommand]
async Task ExecuteSignUpAsync()
{
await Shell.Current.DisplayAlert("Probar botón!",
$"Parece que anda", "OK");
PersonaObj = new mPersona
{
Name = FirstName,
Surname = LastName
};
var validationResult = _validator.Validate(PersonaObj);
if (validationResult.IsValid)
{
ErrorMensajePasa = "Validation Success..!!";
ErrorMensajeGeneral = string.Empty;
}
else
{
ErrorMensajePasa = "Validation Failes..!!";
ErrorMensajeGeneral = validationResult.ToString();
// var nError = validationResult.Errors.Where(e => e.PropertyName.Contains("Name"));
var nError = validationResult.Errors.Where(e => e.PropertyName.Contains(nameof(PersonaObj.Name)));
var sError = validationResult.Errors.Where(e => e.PropertyName.Contains("Surname"));
foreach (var item in nError)
{
FirtNameError = item.ErrorMessage + Environment.NewLine;
}
foreach (var item in sError)
{
LastNameError = item.ErrorMessage + Environment.NewLine;
}
}
}
public bool CanShow { get => firstName.Length > 2 && lastName.Length > 2; }
[ObservableProperty]
string mensaje = string.Empty;
// [ICommand(CanExecute = nameof(CanShow))]
[RelayCommand(CanExecute = nameof(CanShow))]
private void Show()
{
// MessageBox.Show(FullName);
Mensaje = FullName;
}
partial void OnFirstNameChanged(string value)
{
if (CanShow)
{
// MessageBox.Show($"Execute Custom code on {value}");
Mensaje = $"Execute Custom code on {value}";
}
}
}
Steps to Reproduce
- In field Name, write Javier, this is not valid name.
- Click
- In field Name, write JavierX, this is valid name.
- Click don't work6.
6 The first button, change status, but, status word don't change.