I have two properties, AccountTypeId and NavAccountNo. There are also two instance rules, one which validates that the NavAccountNo exists and the second which validates that the AccountTypeId selected is valid for the entered NavAccountNo.
I only want the AccountTypeId validation done if the NavAccountNo is validated as existing, but I also need to make sure that if they change the NavAccountNo to a valid entry the AccountTypeId validation will get done. So I tried doing this
ValidationRules.AddInstanceRule(NavisionAccountExists,
"NavAccountNo", 1);ValidationRules.AddInstanceRule(CreditCardExists,
"AccountTypeId", 2);ValidationRules.AddDependantProperty(
"NavAccountNo", "AccountTypeId");This works nearly perfectly. The only issue is that this displays an error provider error symbol against the AccountTypeId bound control when the NavAccountNo does not exist. The tooltip for the error is the one for the
NavisionAccountExists rule. So I end up with the same error displayed against two properties. How can I get the two properties to trigger each others validation rules but only show the error icon against the relevant property? Hope this makes sense!So your AccountTypeId is getting the same tooltip as NavAccountNo? That doesn't make any sense - the NavisionAccountExists rule shouldn't be running for the AccountTypeId property...
Or are you saying that you just don't want CreditCardExists to run if NavisionAccountExists fails?
I do not want CreditCardExists to run if NavisionAccountExits fails. I thought that the priority parameter I used when adding the rules would facilitate this? I don 't understand the tooltip thing either, but it only happens if I have the AddDependantProperty line. If I comment this out then the tooltip will only display next to the NavAccountNo property, which is correct - but then I don't get the CreditCardExists rule to fire if someone changes the NavAccountNo property and it passes the NavisionAccountExits validation. Hope this is clearer
From: razorkai [mailto:cslanet@lhotka.net]
Sent: Thursday, November 23, 2006 2:25 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Dependant Rule validationI do not want CreditCardExists to run if NavisionAccountExits fails. I thought that the priority parameter I used when adding the rules would facilitate this? I don 't understand the tooltip thing either, but it only happens if I have the AddDependantProperty line. If I comment this out then the tooltip will only display next to the NavAccountNo property, which is correct - but then I don't get the CreditCardExists rule to fire if someone changes the NavAccountNo property and it passes the NavisionAccountExits validation. Hope this is clearer
OK, thanks for letting me know about the tooltip issue - I couldn't figure that one out...
But I think I have a workable answer for the short-circuiting issue. Before implementing it I want to get feedback on the idea though.
One of the things you can do to short-circuit processing for a property is have a rule method explicitly set e.StopProcessing to True, and then return False. Regardless of all other factors, this combination will cause subsequent rules for the property to be ignored.
If I change this slightly I think I can provide an answer to your scenario.
If e.StopProcessing = True causes short-circuiting in all cases (even if the rule returns True), then you could create a required-field rule method that doesn't fail, but does stop processing of subsequent rules.
Or, to be slightly more clever, you could create a rule that doesn't fail, but stops processing of subsequent rules if some other property has 1+ broken rules. This could be a new common rule, because if my scheme works I could see this being quite useful in many cases.
So what you'd do is:
Since PropertyHasNoErrors would not "fail", it wouldn't trigger a tooltip. However, with my proposed e.StopProcessing mod, it would stop all subsequent rules from processing for PropertyB, which gets you the desired result.
What do you think?
Hi Rocky.
That sounds like a good solution. My only concern is that by changing StopProcessing to short circuit in all cases you could break other peoples code that relies on the way it behaves now. This concern may prove to be unfounded, maybe other people in the forum have some feedback?
John.
Copyright (c) Marimer LLC