Dynamic validation based on expression

Dynamic validation based on expression

Old forum URL: forums.lhotka.net/forums/t/10120.aspx


Charleh posted on Tuesday, March 01, 2011

Hi all,

I have a SL project in which I'm struggling with a custom rule implementation - basically I have a bizobj which contains a child collection of 'fields'. Each field has a FieldLabel, FieldValue and ValidationRule property. The validation rule can be any expression which procduces a boolean value and can include any other field from the collection (which is dynamically replaced by the field value at run time)

For example, if I have 4 fields called: Num1, Num2, Num3 and Sum

An expression may look like [Num1] + [Num2] + [Num3] = [Sum]

This expression is evaluated in a business rule and this part is working correctly

The issue I'm having is that when a user changes the value in say 'Num1', only the business rule for Num1 fires - this is expected behaviour, so I decided to add a public method to allow CheckRules to be called on all other fields in the list when a field changes.

This fires the validation rules on the other items as expected, but even though the rules are broken the UI doesn't get notified of the change. I can't raise a propertychanged event for all the fields as this would cause an issue with the audit information log which stores prev/new property values for all changes.

Is there any way of notifying the UI that it needs updating without firing childchanged on the parent or will I need to code round this?

Charleh replied on Tuesday, March 01, 2011

I always figure it out 2 seconds after posting!

Don't know if it's the best way to do it, but the list check fires when the property of a field changes. I just added another property around the setter which notifies the audit that it shouldn't collect any audit change results during the business rule checks, regardless if propertychange notifications hit it. It seems quick enough - I don't think I'll be looking at more than 8-10 fields at a time anyway

If anyone has any other suggestions though, they are welcome!

Copyright (c) Marimer LLC