{"id":614,"date":"2019-07-15T14:41:56","date_gmt":"2019-07-15T18:41:56","guid":{"rendered":"http:\/\/www.markwheeler.com\/wordpress\/?p=614"},"modified":"2019-07-15T14:41:56","modified_gmt":"2019-07-15T18:41:56","slug":"nintex-form-tricks-part-2-set-list-lookup-defaults-to-all-checked","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=614","title":{"rendered":"Nintex Form Tricks, Part 2: Set List Lookup defaults to all checked."},"content":{"rendered":"<p>In the previous post, I had to populate a list lookup control that was filtered by cascading drop-downs. The second task was to default all the training classes as selected.<\/p>\n<p>One option is to add a user-selectable Yes\/No button to select all the tasks. In my form, the data is contained in a Repeater Row control. Having a Select All button in multiple repeater rows would cause a conflict between several rows as the script action is not unique. I&#8217;m including this here for reference.<\/p>\n<p>Assign a Javascript clientID to your Yes\/No button.<br \/>\n<img decoding=\"async\" src=\"http:\/\/54.159.73.21\/wp-content\/uploads\/2019\/07\/selectall.jpg\"><br clear=\"all\"><\/p>\n<p>Add the following lines to the Custom Javascript area on your form settings.<\/p>\n<pre>NWF$('#'+YOURJAVASCRIPTID).click(function(){   \nNWF$('input:checkbox').not(this).prop('checked', this.checked);\n});\n<\/pre>\n<p>If you want no user interaction and just want to select everything by default you can add the following to the Custom Javascript area on your form settings.<\/p>\n<pre>\/\/ Wait for the List Lookup to Render\nNWF.FormFiller.Events.RegisterAfterReady(function(){\n\/\/ We are looking for all checkboxes in the form.\nvar myElement = document.querySelectorAll('input[type=checkbox]')[0];\n\/\/ Mutant Observer setup. This watches for dynamic changes to the DOM\nvar observer = new MutationObserver(function(mutations) {\n\/\/ If there's a checkbox and it's not checked...\nif (document.contains(myElement) &amp;&amp; NWF$('input:checkbox').prop('checked', false)) {\n\/\/ console.log(\"Checkbox Added\"); \n\/\/ Check the box.\nNWF$('input[type=checkbox]').trigger('click');\n\/\/count++\n\/\/console.log(count); \n}\n});\n\/\/ Observer kick off.\nobserver.observe(document, {attributes: false, childList: true, characterData: true, subtree:true});\n});\n<\/pre>\n<p>A couple of things to note:<br \/>\n1. .trigger(&#8216;click&#8217;); is the key here. You could use .prop(&#8216;checked&#8217;, this.checked); But, this does NOT save the change state. Your form will be saved without any selections.<br \/>\n2. attributes: false, must be set. This could set off an infinite loop within the MutationObserver and the page will hang.<br \/>\n3. MutationObserver only works in modern browsers; Firefox, Chrome, MS Edge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post, I had to populate a list lookup control that was filtered by cascading drop-downs. The second task was to default all the training classes as selected. One option is to add a user-selectable Yes\/No button to select all the tasks. In my form, the data is [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2,10,11],"tags":[73],"class_list":["post-614","post","type-post","status-publish","format-standard","hentry","category-computer","category-sharepoint","category-software","tag-nintex-forms"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=614"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/614\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}