This project has moved. For the latest updates, please go here.

People Picker Required Fields Show "You must specify a value..." Message On Form Load

Mar 28, 2016 at 10:16 PM
Hi,
I'm using SPEasyForms v2015.01.01 with SP2010 primarily for the side by side fields (columns) functionality. Great for those long forms! When I use people picker fields and they are set to required, I get the "You must specify a value for this required field." message on new item form load. Multi-line Enhanced fields display the message twice. Is this the expected behavior or am I doing something wrong? I created a very simple OOTB list and have no other javascript/JQuery on the sharePoint form. Any help or workarounds to fix this would be highly appreciated.
Thanks.
Coordinator
Mar 29, 2016 at 12:17 AM
It's definitely not the expected behavior, but I have no idea why you might be seeing this. It sounds a little like an asynchronous post back is occurring that's making those fields think you tried to submit, but there's nothing in my code that should be doing that. Is your form launching in a dialog (i.e. the default behavior for 2010)? If so, try going into advanced settings and telling it not to launch in a dialog and see if that makes any difference. Not that that's a long term solution, but it might give me some clues. I'm assuming that since you didn't mention it, you haven't applied any adapters to those fields (like the default to current user adapter or lookup detail adapter), or to any other fields?

Anyway, I just tested 2013, 2016, and online for required people pickers and enhanced rich text fields and the validation worked just fine (i.e. nothing on load, error messages on submit if left empty). I know you're on 2010 but I don't have a 2010 environment at the moment. I should be able to spin one up and test it by this weekend. I certainly didn't see anything like this when I tested 2015.01.01 on 2010 before releasing it, though I couldn't swear that I specifically tested with required people pickers and enhanced rich text fields.

I wish I could suggest a work around, but this is the first report of an apparent new issue. I'll let you know what I find out when I get a 2010 environment spun up.

Joe
Mar 29, 2016 at 4:38 AM
Joe,
I downloaded the solution again, created a new web application and replicated the list with a people picker and enhanced rich text multi line field (both required). I setup a two column form. I changed the list to have the form displayed in the page and still the same result for the people picker field. Although, the enhanced rich text field was ok on this site, the other site it was showing the required field message - odd. I haven't applied any of the adapters to these fields. I am using IE 11 and windows 7 64 bit. I also set the people picker to allow multiple selections with the same result. I'll check back with when you are able to spin up the 2010 environment. I'll see if I can use some JQuery/JavaScript to hide the required field message before the form is validated. I can also try some of the compatibility mode options.
Thanks again.

I did find that I can keep the multi column rows on the forms aligned by inserting a hr (horizontal rule) in the htmlsnippet container.
Coordinator
Apr 4, 2016 at 10:06 PM
Edited Apr 4, 2016 at 10:09 PM
Ok, as usual I have good news and bad news. The good news is that I've spun up a new 2010 dev machine and I've been able to reproduce your problem(s). The bad news of course is that I have no friggin' clue what the problem is...yet ;).

The problem with the people picker appears to have nothing to do with columns (or anything in the SPEasyForms configuration file for that matter). I say this because it happens with required people pickers even if there is no SPEasyForms configuration for the list at all. If I deactivate SPEasyForms, it goes away, so it's obviously still my problem.

The problem with the enhanced rich text appears to be more complex. So far I've only been able to reproduce it when the field is on a column, and only in Firefox (I did see the double validation error messages, but no validation error messages in IE or Edge). I haven't done enough testing to be sure I know all the edge cases for this one, but it's not as simple as the people picker.

Anyway, I'm looking into it, but this could take some time to track down. In the end, because 2010 handles this stuff so much differently than later versions, I may try to do what you suggest above and just hide the validation errors on the initial page load. That may not be as simple as it sounds though, because in 2010 validation mostly occurs with a full post back, so its difficult to tell the difference between a validation page load and the initial page load (at least, it seems difficult until you figure it out and then you feel stupid...). I'll let you know if I make any progress, but real life/work is pretty busy right now so I have limited cycles to work this. If you make any progress using jQuery/JavaScript to hide the messages pre-validation, I'd love to hear it, and maybe I can include the same approach in the next release (which I can put it pretty quickly if I have a fix).

Joe
Apr 4, 2016 at 11:31 PM
Hi Joe,
Thanks for getting back to me on this! At least I know I'm not the only one getting the problems.

I am still looking to see if I can get some JQuery or JavaScript to work around this. I can hide the required message on page load, but as you mentioned the post back was giving me issues. I'm haven't done much with checks for initial page load or post back in sharePoint, but will see what I can do. I will try to see if I can set a form variable or use the PreSaveAction to get the required message showing after validation if needed. We are planning to migrate to 2013, but that may get pushed back, so I hope we can find an answer. If I do get something to work, I will get back to you.
Coordinator
Apr 5, 2016 at 1:14 AM
Ok, this was bugging me, so I did a little digging and I may have found a way to tell the initial load of the page from a post back. JavaScript doesn't make this easy for security reasons. Anyway I found something on stack overflow that suggested checking:

document.referrer === window.location.href

This seems to reliably evaluate to false on the initial page load of a SharePoint form (document.referrer === "" on initial load) and true on a post back.

I don't think this would always be reliable as in on all web pages; for instance a page could have a link to itself (although why?), in which case it would be a GET not a POST but the above test would be true, but that's just a little self indulgent nonsense. We don't need it to work on all web pages, we just need it to work on SharePoint 2010 forms, and it seems to do that ;)

See if that helps and let me know. I think if I have to put something like this into SPEasyForms proper I will check for _spPageContextInfo.webUIVersion === 4 before running this code, just so it only runs on 2010. If you might be updating to 2013, you might want to do the same in your fix.

Joe
Marked as answer by mcsheaj on 4/5/2016 at 2:16 PM
Coordinator
Apr 5, 2016 at 1:34 AM
Edited Apr 5, 2016 at 4:10 AM
BTW, the duplicate error message on enhanced RTE fields is pretty curious. Most of the alert messages in SharePoint 2010 forms, including the first alert on ERTE fields consist of two nested spans, the outer with a class of ms-formvalidation and the inner with a role of alert (I checked very quickly so double check).

The second alert on ERTE fields has only one span with both a class of ms-formvalidation and a role of alert.

You could use this to strip out the duplicate alert pretty easily, with CSS:

.ms-formvalidation[role='alert'] { display: none; }

or with jQuery:

$(".ms-formvalidation[role='alert']").hide();

Hope this helps some.

Joe
Marked as answer by mcsheaj on 4/5/2016 at 2:16 PM
Apr 5, 2016 at 5:34 AM
Thanks for the suggestions. The document.referrer === window.location.href seems promising; as I only had a few minutes to do a simple test just now as I am doing some training. Earlier I tried some other javascript and asp.net type of postback tips but none worked well. I will have time to try this out more at work in the morning.
Apr 5, 2016 at 8:17 PM
Status update: Woohoo! I was able to resolve the issues using your suggestions.

Since I was also planning to use the PreSaveAction function and SPServices in my form scripts, I tested with/without these and had no issues.
Apr 5, 2016 at 8:18 PM
if (document.referrer === window.location.href) {

    // Show any required field error messages after validation
    //alert ("POSTBACK");
    $('#ctl00_m_g_09f75141_8638_4393_be12_3786729fac4d_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel.ms-error').show();
    $('#ctl00_m_g_09f75141_8638_4393_be12_3786729fac4d_ctl00_ctl05_ctl19_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel.ms-error').show();
    // Hide duplicate required field msg on enhanced multiline text fields 
    $(".ms-formvalidation[role='alert']").hide();  
    
    } else {
       // Hide any required field error messages on form load (fix)
       //  alert ("Initial load");
       $('#ctl00_m_g_09f75141_8638_4393_be12_3786729fac4d_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel.ms-error').hide();
       $('#ctl00_m_g_09f75141_8638_4393_be12_3786729fac4d_ctl00_ctl05_ctl19_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_errorLabel.ms-error').hide(); 
      
       }
Coordinator
Apr 5, 2016 at 9:16 PM
Fantastic. I'll see about trying to work a similar generic solution into SPEasyForms some time reasonably soon. Implementing it should be easy enough, but regression testing can be as PITA ;)

Joe
Coordinator
Apr 6, 2016 at 2:52 AM
I've added Issue 45: People Picker Required Fields Show "You must specify a value..." Message On Form Load to track this issue. I hope to have a fix released in a couple of weeks or so.

Joe
Marked as answer by mcsheaj on 4/5/2016 at 7:52 PM