{"id":1406,"date":"2014-09-03T13:05:32","date_gmt":"2014-09-03T11:05:32","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1406"},"modified":"2014-09-03T14:39:01","modified_gmt":"2014-09-03T12:39:01","slug":"problem-with-the-people-picker-of-sharepoint","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2014\/09\/03\/problem-with-the-people-picker-of-sharepoint\/","title":{"rendered":"Problem with the People Picker of Sharepoint"},"content":{"rendered":"<p>For one of my list I&#8217;ve had a very weird issue: one people picker didn&#8217;t work properly. If I entered a name and clicked to check it, then it didn&#8217;t work. If I saved it and then got back to the form, the value didn&#8217;t appear.<\/p>\n<p>This strange behavior is due to a missing SPAN element with <b>_errorLabel<\/b> as an ID. I have no clue why Sharepoint failed to create this SPAN element&#8230; And the error is related to the <code>EntityEditorCallback<\/code> function that tries to use the SPAN element, but as it doesn&#8217;t exist, it returns NULL and fails the function.<\/p>\n<p>To fix it, I&#8217;m checking if the SPAN element exists, and if not I create it.<br \/>\nThe below code must be called <b>AFTER<\/b> the line in your document that says :<\/p>\n<pre class=\"brush:javascript\">\r\ndocument.write('&lt;script type=\"text\/javascript\" src=\"\/_layouts\/entityeditor.js?rev=vXD0hrzDeHYHbfW8aRSMjA%3D%3D\">&lt;\/' + 'script>');\r\n<\/pre>\n<p>The code to fix this issue is:<\/p>\n<pre class=\"brush:javascript\">\r\n\/\/ some People Picker are broken for an unknown reason...\r\n\/\/ the behavior : we cannot check the name, and the \"default\" value is not set when editing\r\n\/\/ the fix : the span with _errorLabel is not created, so we need to create it\r\nif (typeof EntityEditorCallback === \"function\") {\r\n  var _EntityEditorCallback = EntityEditorCallback;\r\n  window.EntityEditorCallback = function(result,ctx,preventAutoPostBack) {\r\n    var errorControl=document.getElementById(getSubControlID(ctx, 'errorLabel'));\r\n    \/\/ if errorControl doesn't exist then we create it\r\n    if (!errorControl) {\r\n      var e=document.getElementById(ctx);\r\n      var spans=e.getElementsByTagName(\"td\");\r\n      for (var i=0; i&lt;spans.length; i++) {\r\n        if (spans[i].getAttribute(\"colspan\") == 3) {\r\n          spans[i].innerHTML = '<span id=\"'+ctx+'_errorLabel\" class=\"ms-error\"><\/span>';\r\n          break;\r\n        }\r\n      }\r\n    }\r\n    \/\/ call the original function\r\n    _EntityEditorCallback(result,ctx,preventAutoPostBack);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For one of my list I&#8217;ve had a very weird issue: one people picker didn&#8217;t work properly. If I entered a name and clicked to check it, then it didn&#8217;t work. If I saved it and then got back to the form, the value didn&#8217;t appear. This strange behavior is due to a missing SPAN [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[23,13,33],"tags":[156,24,152,158,117],"class_list":["post-1406","post","type-post","status-publish","format-standard","hentry","category-debug","category-niveau-intermediaire","category-programmation","tag-debug","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1406"}],"version-history":[{"count":3,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1406\/revisions"}],"predecessor-version":[{"id":1409,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1406\/revisions\/1409"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}