New Posts New Posts RSS Feed: Need fancy verifier..
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Need fancy verifier..

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: Need fancy verifier..
    Posted: 23-Apr-2014 at 7:08am
In Silverlight I have requirement for Verifier that works like so..

1. 3 fields triggering same verifier. A-Type, B-Customer1, C-Customer2
2. When specific (A) selected I need to make sure either (B) or (C) selected.

I wrote VerifierProvider. Created DelegateVerifier and created static VerifierResult.

Everything works 99%. Here is snippet where I decide what error to return:


if (entity.ReasonEx == ReasonEnum.Lumper)
               {
                    var properties = new List<string>();
                    if (!entity.DriverKey.HasValue && !entity.CarrierKey.HasValue)
                    {
                        properties.Add(PropertyMetadata.DriverKey.Name);
                        properties.Add(PropertyMetadata.CarrierKey.Name);
                    }

                    if (string.IsNullOrEmpty(entity.TripId)) properties.Add(PropertyMetadata.TripId.Name);

                    if (properties.Any())
                        return new VerifierResult(false, "Required when Lumper reason selected", properties.ToArray());
               }


So, if specific "reason" selected and no driver or carrier specified I return both driver and carrier as errrors. Problem is, it's little confusing to user, because they all show as "Required when.." on UI.

Ideally I'd like to attach custom message to each property. But VerifierResult allows me to do multi-property but only one message. In this case I need to say "Either driver OR carrier required when..."
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 24-Apr-2014 at 2:17pm
Hi katit,

In your DelegateVerifier, you should have access to the TriggerContext which gives you information on which property triggers the verifier. You can access it through TriggerContext.TriggerItem.MemberName.
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 24-Apr-2014 at 2:19pm
Yes, I understand. Any of the 3 properties can trigger verifier. But what I want is _different_ messages over each field. So, if this verifier returns verification result for 3 properties I'd like to specify different messages too.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 24-Apr-2014 at 2:58pm
My apologies. I misunderstood your requirements.

Currently, ReasonEx property is the only one that's triggering this DelegateVerifier. And because of that, you're limited to providing one custom message.

Your requirement is that you want to provide custom message per each property that's involved in this validation. To do this, you have to attach a Verifier to the other 3 properties and make them trigger the validation. This is the only way that I can think of to do what you want.

See if you can try the following:

1. Create a DelegateVerifier that you would attach to these 3 properties. Let's call this DriverCarrierDelegateVerifier. Note that you can subclass the RequiredValueVerifier. This is a pre-defined DevForce Verifier. 

See http://drc.ideablade.com/devforce-2012/bin/view/Documentation/validation-create-custom-verifier#HSubclassingapre-definedverifier for more details.

2. Within it, since you know which property is triggering the Verifier through TriggerContext, you can return a VerifierResult with its customized message per property.

3. In your ReasonEx DelegateVerifier, call,

var verifiersToExecute = new List<Verifier> { DriverCarrierDelegateVerifier };
verifierContext.VerifierEngine.Execute(entity, verifiersToExecute, verifierContext);

The above Execute call will trigger the DriverCarrierDelegateVerifier and in turn will trigger the 3 properties to be validated.

Please let me know how it goes.
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 24-Apr-2014 at 3:06pm
I'm still not sure how this will work. I don't have problem with triggering and processing properties. I don't even care which of those 3 properties triggered verifier.

I do want to somehow return return multiple messages along with properties.

Something like this: (obviously it's bad signature suggestion, but illustrates what I need)
return new VerifierResult(false, "MeesageForProperty1", "MessageForProperty2", properties.ToArray());
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 28-Apr-2014 at 11:33am
Unfortunately, we don't currently support the creation of custom message per property via VerifierResult. You can certainly suggest it on our DevForce UserVoice

Since a VerifierResult can only return one message for all properties specified, we have to somehow return specific VerifierResult for the specific property. That's why I suggested the approach above. 


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down