0

So I have a DVWP with an Edit Form. The form uses jQuery tabs to organize the fields for the different roles that edit the item. I would like to show a message at the top of the form if at least one fields fail validation. Is there a simple way to do this that keeps all OTB column validation fully functional?

| improve this question | | | | |
1

I needed a simple method to determine if there was at least on error in a form field on any of the tabs. Because ms-error is present in the DOM before an error has occurred (people picker), I had to find a different way. Also, because different fields render the error message in different ways, I had to account for all methods in my form. What I ended up doing was targeting the three methods that I found.

var varTaskTitleHasError = $("span span[role='alert']").length;
var varTaskDateHasError = $("span #DateTimeFieldErrorMessage").length;
//I only had one People Picker field so the method below might not work when more than one is present.
var varTaskAssignHasError = $("span .ms-error").text();

Then I tested on these variables

if(varTaskTitleHasError > 0 || varTaskDateHasError > 0 || varTaskAssignHasError !== ""){
    ...Do Something
}
else{
    ...Do Nothing
}

So if an error message was found, I did a .show() on my error message that rendered above the tabs.

| improve this answer | | | | |
0

You could try to search for the error message span with class .ms-error and append the column title to your message element in the top of the form.

Could be something like:

$(".ms-error").each(function(){
    $("#myValidationMessage").append($(this).closest("td.ms-formbody nobr").text());
});

You can add this to $(document).ready(), because the page reloads on validation errors.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.