2

We have a list content type in SharePoint 2010. Some fields are mandatory. When not all mandatory fields are filled out, we only get to see the red error message for the date picker field. Once the date picker field is filled out, we get to see the red error messages for all other mandatory fields. Normally I expect to see the error messages for ALL of the mandatory fields that were not filled out.

Why is this and how can this be remediated?

Many thanks!

3

It sounds as if SharePoint is validating DatePicker items first, probably because of the added trouble of pulling the data from it (I think it has PeopleEditor fields in a similar hierarchy). One way you can fix this is to add some JavaScript to your new or edit forms, taking the following general steps:

  1. Open up the forms in Designer and add hidden span tags after the fields that include the error message you want to add. You could also dynamically create this content in JavaScript itself, which is kind of the only way to go if you're using the default new/edit forms (you can use jQuery or a similar DOM selector to find the fields in the HTML). (Word of warning, though: I can tell you right now that it is a MASSIVE pain in the rear to find PeoplePicker fields in the DOM, particularly in 2007 and 2010. Dates are pretty straightforward though.)

  2. Either way, you'll want to create a companion JS file with a function in it called PreSaveAction().

  3. Run whatever validation you want to run in this function. Basically, if everything is validated OK you should return "true" and if there's anything wrong you should return "false".

Unfortunately that is the best way that I know of to do this. There isn't a switch you can flip in Settings or wherever that says "validate everything all at once, not just Picker controls". Also, just because you're doing client-side validation doesn't mean that SP won't still do the same server-side stuff it's currently doing, so if you change a business rule in your JS function but don't update it in SharePoint you will probably have validation issues.

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.