{"id":125504,"date":"2016-08-31T10:47:10","date_gmt":"2016-08-31T08:47:10","guid":{"rendered":"http:\/\/guriddo.net\/?post_type=kbe_knowledgebase&#038;p=125504"},"modified":"2016-08-31T10:47:10","modified_gmt":"2016-08-31T08:47:10","slug":"display-hidden-fields-from-grid-in-edit-form-as-texts","status":"publish","type":"kbe_knowledgebase","link":"http:\/\/guriddo.net\/?kbe_knowledgebase=display-hidden-fields-from-grid-in-edit-form-as-texts","title":{"rendered":"Display hidden fields from grid in edit form as texts"},"content":{"rendered":"<p>There are situation where we need to display the fields in edit form as texts, without a need to update it &#8211; just for information. In this article I will explain how to achieve this.<\/p>\n<p>In Guriddo jqGrid there is no build-in way to display certain fields in forms as text for information purposes. Fortunately we have a custom functions with which we can do this. <\/p>\n<p>In this example we will use <em>custom_element<\/em> and <em>custom_value<\/em> in <a href=\"http:\/\/www.trirand.com\/jqgridwiki\/doku.php?id=wiki:common_rules#editoptions\">editoptions object<\/a>. The another requirement is that the field should be hidden in grid, but displayed into the form. Below are the settings in colModel which will do this:<br \/>\n[js]<br \/>\ncolModel: [<br \/>\n&#8230;<br \/>\n   {<br \/>\n      label: &#8216;Freigh&#8217;,<br \/>\n      name: &#8216;Freight&#8217;,<br \/>\n      width: 150,<br \/>\n      hidden : true,<br \/>\n      editable: true,<br \/>\n      edittype: &quot;custom&quot;,<br \/>\n      editoptions: {<br \/>\n         custom_value: getFreightElementValue,<br \/>\n         custom_element: createFreightTextElement<br \/>\n      },<br \/>\n      editrules : { edithidden : true }<br \/>\n   },<br \/>\n&#8230;<br \/>\n],<br \/>\n[\/js]<\/p>\n<p>In order not to display the field in grid, but in edit form we need to set the hidden option to true and edithidden option to true in <a href=\"http:\/\/www.trirand.com\/jqgridwiki\/doku.php?id=wiki:common_rules#editrules\">editrules object<\/a><\/p>\n<p>Now the field should be defined as editable and tell that a custom edit will be applied. This is done with <em>editable: true<\/em> and <em>edittype: &#8220;custom&#8221;<\/em> options in colModel. When a custom edit type is used we need to define two functions in editoptions &#8211; <em>custom_element<\/em>, which is responsible for the creation of our element and <em>custom_value<\/em> which is responsible for the manipulation of the value for that element. Bello are our two functions.<\/p>\n<p>[js]<br \/>\nfunction createFreightTextElement(value, editOptions) {<br \/>\n   return $(&quot;&lt;span&gt;&quot;+value+&quot;&lt;\/span&gt;&quot;);<br \/>\n}<\/p>\n<p>function getFreightElementValue(elem, oper, value) {<br \/>\n   if (oper === &quot;set&quot;) {<br \/>\n      $(elem).text(value)<br \/>\n   }<br \/>\n   if (oper === &quot;get&quot;) {<br \/>\n      return $(elem).text();<br \/>\n   }<br \/>\n}<br \/>\n[\/js]<\/p>\n<p>As can be seen the function which creates the element <em>createFreightTextElement<\/em> create a simple span element and append the value in this element. The function <em>getFreightElementValue<\/em> set the value in form when we walk through the records with navigator buttons (oper = set) and return the value when we push the <em>Submit<\/em> button form (oper= get). In case if there is a no need to submit this value to the server a serrializeEditData event should be defined in order to remove this Element. Below is the code that do this.<br \/>\n[js]<br \/>\n$(&quot;#jqGrid&quot;).navGrid(&quot;#jqGridPager&quot;,<br \/>\n   { edit: true, add: false, del: false, search: false, refresh: true, view: false, align: &quot;left&quot; },<br \/>\n   \/\/ edit form options<br \/>\n   {<br \/>\n      closeAfterEdit: true,<br \/>\n      serializeEditData:function(data){<br \/>\n         delete data[&#8216;Freight&#8217;];<br \/>\n         return data;<br \/>\n      }<br \/>\n   }<br \/>\n);<br \/>\n[\/js]<\/p>\n<p>That is all. The example can be seen in our <a href=\"http:\/\/guriddo.net\/demo\/guriddojs\/edit_add_delete\/dialogs_text_fields\/\">demo page here<\/a><\/p>\n<p>Kind Regards,<br \/>\nTony Tomov<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are situation where we need to display the fields in edit form as texts, without a need to update it &#8211; just for information. In this article I will explain how to achieve this. In Guriddo jqGrid there is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","kbe_taxonomy":[94,91],"kbe_tags":[],"_links":{"self":[{"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/kbe_knowledgebase\/125504"}],"collection":[{"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/kbe_knowledgebase"}],"about":[{"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/types\/kbe_knowledgebase"}],"author":[{"embeddable":true,"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/guriddo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125504"}],"version-history":[{"count":5,"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/kbe_knowledgebase\/125504\/revisions"}],"predecessor-version":[{"id":125509,"href":"http:\/\/guriddo.net\/index.php?rest_route=\/wp\/v2\/kbe_knowledgebase\/125504\/revisions\/125509"}],"wp:attachment":[{"href":"http:\/\/guriddo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125504"}],"wp:term":[{"taxonomy":"kbe_taxonomy","embeddable":true,"href":"http:\/\/guriddo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fkbe_taxonomy&post=125504"},{"taxonomy":"kbe_tags","embeddable":true,"href":"http:\/\/guriddo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fkbe_tags&post=125504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}