{"id":1394,"date":"2016-01-29T12:30:40","date_gmt":"2016-01-29T17:30:40","guid":{"rendered":"http:\/\/xlinesoft.com\/blog\/?p=1394"},"modified":"2017-02-13T15:24:50","modified_gmt":"2017-02-13T20:24:50","slug":"executing-your-code-after-inline-add-or-edit","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2016\/01\/29\/executing-your-code-after-inline-add-or-edit\/","title":{"rendered":"Executing your code after Inline Add or Edit"},"content":{"rendered":"<p>PHPRunner\/ASPRunnerPro\/ASPRunner.NET have a couple of handy events that allow you execute your own code after record was added or edited in inline or in popup mode. For instance, you may want to change some fields appearance based on new data modified or redirect user to view page after record was added in popup mode.<\/p>\n<h2>1. Change text color and background color after Inline Add\/Edit<\/h2>\n<p>To do so add the following code to <strong>List page: Javascript OnLoad<\/strong> event. <\/p>\n<pre name=\"code\" class=\"javascript:nocontrols\">function funcAfter(fieldsData) {\r\n    for (f in fieldsData) {\r\n        var field = fieldsData[f];\r\n        if (field.name == 'status') {\r\n            if (field.value == 'Pending') {\r\n                field.container.closest('td').css('background', 'red');\r\n                field.container.closest('td').css('color', 'white');\r\n            } else if (field.value == 'Active') {\r\n                field.container.closest('td').css('background', 'orange');\r\n                field.container.closest('td').css('color', 'darkblue');\r\n            }\r\n        }\r\n    }\r\n}\r\nthis.on('afterInlineEdit', funcAfter);\r\nthis.on('afterInlineAdd', funcAfter);<\/pre>\n<p>In this event we evaluate the value of &#8216;status&#8217; field and then change CSS properties of the cell when this field is located. To save the amount of coding we define the <strong>funcAfter<\/strong> function and make it run after both Inline Add and Edit. <\/p>\n<p>This code will work without any changes in PHPRunner, ASPRunnerPro and ASPRunner.NET apps. Here is how it&#8217;s going to look. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2016\/01\/scr.png\" alt=\"\" title=\"scr\" width=\"545\" height=\"156\" class=\"alignnone size-full wp-image-1395\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2016\/01\/scr.png 545w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2016\/01\/scr-300x85.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2016\/01\/scr-150x42.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2016\/01\/scr-400x114.png 400w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><br \/>\n<!--more--><\/p>\n<h2>2. Redirect user to View page after adding new record in popup<\/h2>\n<p>Do not forget to replace &#8220;documents&#8221; with your table name. It also assumes that key column name is &#8220;id&#8221;. <\/p>\n<p><strong>PHPRunner<\/strong><\/p>\n<pre name=\"code\" class=\"javascript:nocontrols\">\r\nfunction funcAfter(fieldsData) {\r\n    for (f in fieldsData) {\r\n        var field = fieldsData[f];\r\n        if (field.name == 'id') {\r\n            window.location.href = \"documents_view.php?editid1=\" + field.value;\r\n        }\r\n    }\r\n}\r\nthis.on('afterInlineAdd', funcAfter);\r\n<\/pre>\n<p><strong>ASPRunnerPro<\/strong><\/p>\n<pre name=\"code\" class=\"javascript:nocontrols\">\r\nfunction funcAfter(fieldsData) {\r\n    for (f in fieldsData) {\r\n        var field = fieldsData[f];\r\n        if (field.name == 'id') {\r\n            window.location.href = \"documents_view.asp?editid1=\" + field.value;\r\n        }\r\n    }\r\n}\r\nthis.on('afterInlineAdd', funcAfter);\r\n<\/pre>\n<p><strong>ASPRunner.NET<\/strong><\/p>\n<pre name=\"code\" class=\"javascript:nocontrols\">\r\nfunction funcAfter(fieldsData) {\r\n    for (f in fieldsData) {\r\n        var field = fieldsData[f];\r\n        if (field.name == 'id') {\r\n            window.location.href = \"view?editid1=\" + field.value;\r\n        }\r\n    }\r\n}\r\nthis.on('afterInlineAdd', funcAfter);\r\n<\/pre>\n<p>More info on <strong>fieldsData<\/strong> structure from the manual:<\/p>\n<pre name=\"code\" class=\"javascript:nocontrols\">\r\nfieldsData = {\r\nname: field name,\r\nvalue: raw field value as it appears in the database,\r\ntext: field value with formatting applied if any,\r\ncontainer:  jQuery object, a container, where field value will be inserted\r\n}\r\n<\/pre>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHPRunner\/ASPRunnerPro\/ASPRunner.NET have a couple of handy events that allow you execute your own code after record was added or edited in inline or in popup mode. For instance, you may want to change some fields appearance based on new data modified or redirect user to view page after record was added in popup mode. 1. Change text color and background color after Inline Add\/Edit To do so add the following code to List page: Javascript OnLoad event. function funcAfter(fieldsData) { for (f in fieldsData) {&#8230;<span class=\"clearfix clearfix-post\"><\/span><a href=\"https:\/\/xlinesoft.com\/blog\/2016\/01\/29\/executing-your-code-after-inline-add-or-edit\/\" class=\"more-link\">Continue Reading <span class=\"screen-reader-text\">&#8220;Executing your code after Inline Add or Edit&#8221;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1394","post","type-post","status-publish","format-standard","hentry","category-php-category"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1394"}],"version-history":[{"count":5,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1394\/revisions"}],"predecessor-version":[{"id":1617,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1394\/revisions\/1617"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}