Hello,
I have to validate a control against multiple different conditions. I have created a Custom Condition class and put my conditions in the Matches subroutine.
What I'd like to do is to customize also the Notification settings text that appears when one of the conditions is not matched. I can do this by passing the Control object and Validator object in the constructor of my class. The problem is that the Matches subroutine is not raised when the control value is empty, and so I can't customize the message in the "isRequired" condition is True.
To be more specific:
If the condition 1 is false, notification text has to be "Condition 1 not satisfied"
If the condition 2 is false, notification text has to be "Condition 2 not satisfied"
If the value is empty (and isRequired is true), notification text has to be "Value mandatory"
I'm not able to do the last one because Matches event is not raised when leaving the control with value empty, so notification text remains the older one (for example "Condition 2 not satisfied").
Hi,
Thank you for contacting Infragistics Developer Support.
I am glad that you have resolved your issue. Let me know if you have any additional questions.
Sorry for the late reply.
With your last solution the problem of retaining the correct tooltip message after calling Validate method on validator component is solved, but there is a drawback: after the validation, if you enter a textbox and delete the text, the validation message doesn't change to "This field is required!!" but remains the custom one. That's because the NotificationSettings.Text property doesn't contain the generic error message anymore but the custom one.
The only way I've found to manage this has been to use this code on ValidationError event (vb.net)
Public Sub ValidatorGenerico_ValidationError(ByVal sender As Object, ByVal e As Infragistics.Win.Misc.ValidationErrorEventArgs) For i As Integer = 0 To e.Validation.Errors.Count - 1 Dim errore As Infragistics.Win.Misc.ValidationResult = e.Validation.Errors(i) If TypeOf errore.ValidationSettings.Condition Is MyCustomCondition Then If errore.Status = Infragistics.Win.Misc.ValidationStatus.ConditionFailure Then errore.ValidationSettings.NotificationSettings.Text = errore.ValidationSettings.Condition.ToString() If Not IsNothing(e.Control) Then e.NotificationSettings.Text = errore.ValidationSettings.NotificationSettings.Text Else errore.ValidationSettings.NotificationSettings.Text = errore.ValidationSettings.NotificationSettings.Tag If Not IsNothing(e.Control) Then e.NotificationSettings.Text = errore.ValidationSettings.NotificationSettings.Text End If End If Next End Sub
(ValidatorGenerico is my ultravalidator component)
I store the generic error message in NotificationSettings.Tag property of each control and so i change then NotificationSettings.Text property on the basis of the Status error value choosing from the custom one or the generic one.
Maybe it's not the best workaround but it's working fine for me right now.
Regards,
Claudio
Hello Claudio,
I am just checking about the progress of this issue. Let me know if you need my further assistance on it.
Thank you for using Infragistics Components.
Thank you for your feedback.
To have custom messages appear you need to call ultraValidator1_ValidationError event handler from button1_Click. This is possible if you send to Validate method each control you need to validate. As you may have many controls on the form it is better to use a workaround. Instead of calling each control you need to validate, you can run one more time Validate method. This will fix the error messages issue.
Please check attached solution and let me know if this is what you are looking for or if I am missing something.
Hello Milka,
Your example reflects what I'm doing right now in my form. The only problem, and you can notice that in your last solution project, is that after you click the "Validate" button and the MessageBox "Please fill all fields correct" appears, the notification tooltip message on the 2 textboxes is reset to "The field is required!" (you can see it by passing the mouse on the error icon) while before was "String must be longer than 5...".If you enter and leave the 2 textboxes again the message returns the custom one.
My question is if there is a way to not reset the tooltip message to the default value (the one of the empty condition) when you Validate the form.
Thanks!
Claudio Di Flumeri