{"id":215,"date":"2014-05-07T14:43:27","date_gmt":"2014-05-07T14:43:27","guid":{"rendered":"http:\/\/www.se80.co.uk\/training-education\/?p=215"},"modified":"2019-02-23T00:55:31","modified_gmt":"2019-02-23T00:55:31","slug":"jquery-delegated-assignment","status":"publish","type":"post","link":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/","title":{"rendered":"jQuery delegated assignment"},"content":{"rendered":"<p>This is just a basic snippet of jQuery information\u00a0from an SAP point of view to hep point myself and other SAP developer in the right direction when integrating Javascrip and jQuery into your\u00a0BSP applications.<\/p>\n<p>I needed to understand this\u00a0because I had a BSP that was displaying a table of\u00a0editable data, when the user updated an individual field it had implication for other fields. The application therefore\u00a0captured that a user had changed a field and re-drew the table based on the new data. When I did this using the direct jQuery assignment all the\u00a0event triggers were lost when the AJAX re-drew the table. I then spent ages trying to find a way around this or\u00a0to reload the\u00a0instructions. Its turned out I just needed to use\u00a0Delegated method described below and everything worked fine.<\/p>\n<p><strong><br \/>\nDelegated jQuery\u00a0instructions &#8211; <\/strong>Delegates the\u00a0job of catching an event\u00a0to the overall container.<\/p>\n<p>$(&#8220;#tabDiv&#8221;).delegate(&#8216;input[name=&#8221;myfield&#8221;]&#8217;, &#8216;focus&#8217;, function() {<br \/>\nalert(&#8216;delegate&#8217;);<br \/>\n});<\/p>\n<p>Your instruction is assigned to the overall container (ID=tabDiv)\u00a0so that any input fields with the name &#8220;myfield&#8221; within the container\u00a0 will trigger this functionality. This means that if further fields are added within the container\u00a0via ajax\/javascript they will be picked up.<\/p>\n<p>This is very useful when you are displaying values which are updated using an\u00a0AJAX function, because even if the\u00a0function re-draws the field with the same attribute names they will not get picked up by the jQuery listener unless you use the delegated method.<\/p>\n<p><strong><br \/>\nNon-delegated (direct) jQuery\u00a0instructions\u00a0&#8211; <\/strong>Individual\u00a0elements are directly responsible for any relevant events<br \/>\n$(&#8216;input[name=&#8221;myfield&#8221;]&#8217;).focus(function() {<br \/>\nalert(&#8216;non_delagate&#8217;);<br \/>\n});<\/p>\n<p>Using the direct method each input\u00a0field with name &#8220;myfield&#8221; is\u00a0assigned the instruction on an\u00a0individual basis.\u00a0\u00a0If any new fields get create or\u00a0these fields get re-created via\u00a0AJAX, they won&#8217;t have been there to hear the instruction and therefore will not respond.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is just a basic snippet of jQuery information\u00a0from an SAP point of view to hep point myself and other SAP developer in the right direction when integrating Javascrip and jQuery into your\u00a0BSP applications. I needed to understand this\u00a0because I had a BSP that was displaying a table of\u00a0editable data, when the user updated an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>jQuery delegated assignment - SAP Help, Training and Education<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"jQuery delegated assignment - SAP Help, Training and Education\" \/>\n<meta property=\"og:description\" content=\"This is just a basic snippet of jQuery information\u00a0from an SAP point of view to hep point myself and other SAP developer in the right direction when integrating Javascrip and jQuery into your\u00a0BSP applications. I needed to understand this\u00a0because I had a BSP that was displaying a table of\u00a0editable data, when the user updated an [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/\" \/>\n<meta property=\"og:site_name\" content=\"SAP Help, Training and Education\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-07T14:43:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-23T00:55:31+00:00\" \/>\n<meta name=\"author\" content=\"se80\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"se80\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/\",\"url\":\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/\",\"name\":\"jQuery delegated assignment - SAP Help, Training and Education\",\"isPartOf\":{\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/#website\"},\"datePublished\":\"2014-05-07T14:43:27+00:00\",\"dateModified\":\"2019-02-23T00:55:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/ddc6a049c1b0790f62d70278be75e511\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.se80.co.uk\/training-education\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"jQuery delegated assignment\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/#website\",\"url\":\"https:\/\/www.se80.co.uk\/training-education\/\",\"name\":\"SAP Help, Training and Education\",\"description\":\"Learn SAP\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.se80.co.uk\/training-education\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/ddc6a049c1b0790f62d70278be75e511\",\"name\":\"se80\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3fd4e388f05bf3c763e46cd1f77afeb2?s=96&d=retro&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3fd4e388f05bf3c763e46cd1f77afeb2?s=96&d=retro&r=g\",\"caption\":\"se80\"},\"url\":\"https:\/\/www.se80.co.uk\/training-education\/author\/se80\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"jQuery delegated assignment - SAP Help, Training and Education","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/","og_locale":"en_US","og_type":"article","og_title":"jQuery delegated assignment - SAP Help, Training and Education","og_description":"This is just a basic snippet of jQuery information\u00a0from an SAP point of view to hep point myself and other SAP developer in the right direction when integrating Javascrip and jQuery into your\u00a0BSP applications. I needed to understand this\u00a0because I had a BSP that was displaying a table of\u00a0editable data, when the user updated an [&hellip;]","og_url":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/","og_site_name":"SAP Help, Training and Education","article_published_time":"2014-05-07T14:43:27+00:00","article_modified_time":"2019-02-23T00:55:31+00:00","author":"se80","twitter_card":"summary_large_image","twitter_misc":{"Written by":"se80","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/","url":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/","name":"jQuery delegated assignment - SAP Help, Training and Education","isPartOf":{"@id":"https:\/\/www.se80.co.uk\/training-education\/#website"},"datePublished":"2014-05-07T14:43:27+00:00","dateModified":"2019-02-23T00:55:31+00:00","author":{"@id":"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/ddc6a049c1b0790f62d70278be75e511"},"breadcrumb":{"@id":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.se80.co.uk\/training-education\/jquery-delegated-assignment\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.se80.co.uk\/training-education\/"},{"@type":"ListItem","position":2,"name":"jQuery delegated assignment"}]},{"@type":"WebSite","@id":"https:\/\/www.se80.co.uk\/training-education\/#website","url":"https:\/\/www.se80.co.uk\/training-education\/","name":"SAP Help, Training and Education","description":"Learn SAP","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.se80.co.uk\/training-education\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/ddc6a049c1b0790f62d70278be75e511","name":"se80","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.se80.co.uk\/training-education\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3fd4e388f05bf3c763e46cd1f77afeb2?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3fd4e388f05bf3c763e46cd1f77afeb2?s=96&d=retro&r=g","caption":"se80"},"url":"https:\/\/www.se80.co.uk\/training-education\/author\/se80\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":9,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/posts\/215\/revisions\/224"}],"wp:attachment":[{"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.se80.co.uk\/training-education\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}