-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
feature: Possibility to change validation rules dymamically #71
Comments
Hey @ili 👋, Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially. https://opencollective.com/reactiveui
|
I think the validation rules are stored in a dictionary at the moment so should be possible. I got some other stuff happening at the moment so wouldn't be able to immediately get to it. But reasonable request. |
Currently, you can achieve the described behavior by doing the following: // Listen to Model and IpAddress changes and
// require IpAddress property to not be empty
// only if Model equals to Models.A.
var ipAddressRule = this
.WhenAnyValue(x => x.IpAddress)
.CombineLatest(
this.WhenAnyValue(x => x.Model),
(ipAddress, model) =>
model == Models.A &&
!string.IsNullOrEmpty(ipAddress) ||
model == Models.B && ...);
this.ValidationRule(
x => x.IpAddress,
ipAddressRule,
"IP address required."); The code is based on a new feature introduced in #58 |
Now it should be possible to remove validation rules via a call to var cleanup = new CompositeDisposable();
// Attach a validation rule to the IValidatableViewModel.
this.ValidationRule(
viewModel => viewModel.Name,
name => string.IsNullOrWhiteSpace(name),
"Name shouldn't be empty.")
.DisposeWith(cleanup);
// Detach and dispose the validation rule.
cleanup.Dispose(); |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hello, firstly thanks for your great project.
It would be great if validation would support dynamic validation rules change: for example, i do deed to configure some hardware, different options are available for different models, for ex. "Model A" can be connected either via TCP/IP or via RS232, "Model B" supports RS232 only, so for the first TCP/IP settings required, for the second - RS232.
So i do need smth like:
The text was updated successfully, but these errors were encountered: