views:

457

answers:

1

Ok, this should be a really simple thing to do, and I'm either missing something, or going about it wrong.

Facts:

  1. Silverlight 4, using the Toolkit and using DataForms / DataFields, but NOT using a validation summary.

  2. Using a Templated Dataform, simple new / edit user form with usual fields like username, firstname, etc, plus Password and Confirm Password.

  3. I want to validate so that if they are editing an existing user, and the password fields are blank, let it go through. Otherwise, make sure the passwords are the same. (This works already using a class level custom validator on my model.)

  4. If the validation fails in #3, then alert the user by putting the usual clues on the Password field. (red border, message if you click in the field)

I can do everything now up through #3. But if the error occurs, then the error is shown as a form error, not a field error (which makes sense since the validation is on the class, not the property). I can not find a way to mark up my field to show the error. Since I'm not using a validation summary (for design reasons) the error just never shows up for the user.

Has anyone else done this, or can they send me to an example of a data form with password fields that does not use a Validation Summary so I can see how they solved it?

My two current options that I see are to manually mark the data field myself. OR, I'll build my own method of display full form errors that doesn't repeat errors like the validation summary does. (IE, I need a validation summary that ONLY shows form errors - not field errors.)

Thanks

+1  A: 

Ok, I solved this problem. Here are some tips:

  1. In my xaml's .cs code, I was validating my object by calling TryValidate on my object. This isn't a good idea if you are NOT using the built in DataForm command buttons. If using your own custom buttons then be sure to call the DataForm.ValidateItem() method to make sure all of the errors get outputted to the ValidationSummary properly. (in my case, nothing was ever making it to the validationsummary since I wasn't have the form do the validation.)

  2. You can tell the ValidationSummary to only show object level errors. (Property errors still show up, but only on the field.) To do this assign like so:

    myDataform.ValidationSummary.Filter = ValidationSummaryFilters.ObjectErrors;

See the ValidationSummaryFilters for more info.

This worked for me. My object validation would show up in the validation summary and the property errors only on the properties. Now I just need to style the validation summary the way I want to make it work better for my design.

Vulgrin