{"id":1386,"date":"2014-06-20T15:39:24","date_gmt":"2014-06-20T13:39:24","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1386"},"modified":"2014-09-26T08:11:30","modified_gmt":"2014-09-26T06:11:30","slug":"showhide-a-sharepoint-fields-in-the-newform-editform-and-dispform","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2014\/06\/20\/showhide-a-sharepoint-fields-in-the-newform-editform-and-dispform\/","title":{"rendered":"Show\/Hide a Sharepoint fields in the NewForm, EditForm and DispForm"},"content":{"rendered":"<p>With the Sharepoint WebServices it&#8217;s possible to hide a field into the NewForm, the Editform and\/or the DispForm.<br \/>\nYou&#8217;ll need to use JavaScript with jQuery and <a href=\"http:\/\/spservices.codeplex.com\/\">SPServices<\/a>. It&#8217;s the <a href=\"http:\/\/spservices.codeplex.com\/wikipage?title=UpdateList&#038;referringTitle=Lists\">UpdateList service<\/a> that will do the trick.<\/p>\n<p>Once you have loaded the both librairies you can use the below code:<\/p>\n<pre class=\"brush:javascript\">\r\nvar fieldsToUpdate = '&lt;Fields>';\r\nfieldsToUpdate += '&lt;Method ID=\"1\">&lt;Field Type=\"Text\" Name=\"My_x0020_Field\" DisplayName=\"My Field\" ShowInDisplayForm=\"FALSE\" ShowInEditForm=\"FALSE\" ShowInNewForm=\"FALSE\">&lt;\/Field>&lt;\/Method>';\r\nfieldsToUpdate += '&lt;\/Fields>';\r\n\r\n$().SPServices({\r\n  operation: \"UpdateList\",\r\n  listName: \"Name of the list\",\r\n  listProperties:\"\",\r\n  updateFields: fieldsToUpdate,\r\n  newFields: \"\",\r\n  deleteFields: \"\",\r\n  listVersion: \"\",\r\n  completefunc: function (xData, Status){}\r\n});\r\n<\/pre>\n<p>As explained into this <a href=\"http:\/\/stackoverflow.com\/questions\/13521292\/lists-web-service-updatelist-fails-with-attempted-to-use-an-object-that-has-cea\">Stackoverflow&#8217;s question<\/a> you must provide a minimum of three mandatory properties, and in this order:<\/p>\n<ol>\n<li>Type<\/li>\n<li>Name<\/li>\n<li>DisplayName<\/li>\n<\/ol>\n<p>The <b>Type<\/b> must reflect the type of your field. This information is available into the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/office\/ms437580%28v=office.14%29.aspx\">MSDN documentation<\/a>. The most common values should be <b>Boolean | Calculated | Choice | Currency | DateTime | Integer | Lookup | LookupMulti | MultiChoice | Number | Text | User | UserMulti<\/b>.<\/p>\n<p>The <b>Name<\/b> is the internal name (usually the spaces are replaced with &#8220;_x0020_&#8221;).<\/p>\n<p>And for each form (<b>ShowInDisplayForm | ShowInEditForm | ShowInNewForm<\/b>) you can set them to <b>TRUE<\/b> or <b>FALSE<\/b> (it seems to be case sensitive ?!). More properties are available into the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/office\/ms437580%28v=office.14%29.aspx\">MSDN documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the Sharepoint WebServices it&#8217;s possible to hide a field into the NewForm, the Editform and\/or the DispForm. You&#8217;ll need to use JavaScript with jQuery and SPServices. It&#8217;s the UpdateList service that will do the trick. Once you have loaded the both librairies you can use the below code: var fieldsToUpdate = &#8216;&lt;Fields>&#8217;; fieldsToUpdate += [&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":[13,33],"tags":[24,152,158,117],"class_list":["post-1386","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1386","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=1386"}],"version-history":[{"count":5,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1386\/revisions\/1419"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}