Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple validations to a single property #3

Closed
alexmartinezm opened this issue Mar 14, 2019 · 2 comments
Closed

Add multiple validations to a single property #3

alexmartinezm opened this issue Mar 14, 2019 · 2 comments
Assignees
Labels
bug Something isn't working outdated

Comments

@alexmartinezm
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Actually, if you try to add two validations to the same property, eg Password, in the ValidationContext you would do it like this:

[]
this.ValidationRule(
     vm => vm.Password,
     password => !string.IsNullOrEmpty(password),
     "Password is required.");

this.ValidationRule(
     vm => vm.Password,
     password => password.Length > 5,
     "Password minimum length is 5.");
[]

And from the View you would bind to the Password property like this:

[]
this.BindValidation(ViewModel, vm => vm.Password, view => view.PasswordErrorMessage.Text)
    .DisposeWith(disposables);
[]

The problem by doing this is that from the ValidationBindings, used by the ViewForExtensions, it looks up only for the first or default validation rule (see ResolveFor methods in ValidationContextExtensions).

Describe the solution you'd like
Add support for multiple validations in the same property since it's supported in the ValidationContext side.

Describe suggestions on how to achieve the feature
Basically, if more than one property matches the query in the ResolveFor method then unless the Formatter has been provided, it should throw a custom exception like MultipleValidationNotSupportedException.

On the other side, we should provide Mixins to give support for multiple validation scenarios.

@alexmartinezm alexmartinezm self-assigned this Mar 14, 2019
@alexmartinezm alexmartinezm added this to In progress in Feature Smashing Mar 14, 2019
@alexmartinezm alexmartinezm removed this from In progress in Feature Smashing Mar 14, 2019
@alexmartinezm alexmartinezm added this to In progress in Bug Stomping Mar 14, 2019
@alexmartinezm alexmartinezm added bug Something isn't working enhancement New feature or request labels Mar 14, 2019
Bug Stomping automation moved this from In progress to Done Mar 14, 2019
@alexmartinezm alexmartinezm moved this from Done to On Hold - Upstream Issue in Bug Stomping Mar 14, 2019
@alexmartinezm alexmartinezm moved this from On Hold - Upstream Issue to In progress in Bug Stomping Mar 14, 2019
@alexmartinezm alexmartinezm reopened this Mar 14, 2019
@alexmartinezm alexmartinezm removed the enhancement New feature or request label Mar 14, 2019
@worldbeater
Copy link
Collaborator

worldbeater commented Mar 16, 2019

On the other side, we should provide Mixins to give support for multiple validation scenarios.

I'd prefer this option over throwing exceptions ✨

@lock
Copy link

lock bot commented Jun 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label Jun 24, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated
Projects
Bug Stomping
  
Done
Development

No branches or pull requests

2 participants