<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hubpsot Form clearing check boxes when leveraging JavaScript in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210497#M8746</link>
    <description>&lt;P&gt;I am currently attempting to leverage JS to map clicks on a 'pseudo' checkbox to the actual form checkboxes so that the data sent from the form can still be added to our workflow, and maintain contact properties for the user. A partial code snippet is shown below.&lt;/P&gt;&lt;PRE&gt;/**
 * Handles the click event and delegates what state the checkboxes should be in
 *  @author - Ben G.
 */
function handleClickEvent(isChecked, element) {&lt;BR /&gt;switch(isChecked) {
    case true:
      element.prop("checked", true).change();
      break;
    case false:
      element.prop("checked", false).change();
      break;
    case null:
      console.log("Something is awry the value of checked is: " + isChecked);
  }
    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I am using the&amp;nbsp;.change() function in order to make the change on the HubSpot&amp;nbsp;side of the form. However, the issue that I am running into is that once the user goes to fill out the form, and they move onto a different form field, the checkboxes are immediately cleared. This behavior doesn't occur when the user actually clicks the checkboxes, so this has left me to be rather stumped.&lt;/P&gt;&lt;P&gt;Any help regarding this issue will be greatly appreciated, thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 15:45:25 GMT</pubDate>
    <dc:creator>ben_groneman</dc:creator>
    <dc:date>2018-10-05T15:45:25Z</dc:date>
    <item>
      <title>Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210497#M8746</link>
      <description>&lt;P&gt;I am currently attempting to leverage JS to map clicks on a 'pseudo' checkbox to the actual form checkboxes so that the data sent from the form can still be added to our workflow, and maintain contact properties for the user. A partial code snippet is shown below.&lt;/P&gt;&lt;PRE&gt;/**
 * Handles the click event and delegates what state the checkboxes should be in
 *  @author - Ben G.
 */
function handleClickEvent(isChecked, element) {&lt;BR /&gt;switch(isChecked) {
    case true:
      element.prop("checked", true).change();
      break;
    case false:
      element.prop("checked", false).change();
      break;
    case null:
      console.log("Something is awry the value of checked is: " + isChecked);
  }
    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I am using the&amp;nbsp;.change() function in order to make the change on the HubSpot&amp;nbsp;side of the form. However, the issue that I am running into is that once the user goes to fill out the form, and they move onto a different form field, the checkboxes are immediately cleared. This behavior doesn't occur when the user actually clicks the checkboxes, so this has left me to be rather stumped.&lt;/P&gt;&lt;P&gt;Any help regarding this issue will be greatly appreciated, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 15:45:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210497#M8746</guid>
      <dc:creator>ben_groneman</dc:creator>
      <dc:date>2018-10-05T15:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210518#M8750</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72592"&gt;@ben_groneman&lt;/a&gt;&amp;nbsp;- Is this an embed code? or the form module in the Design Manager?&lt;/P&gt;&lt;P&gt;If it's a form module, you should use the global form events to wrap your code after the form has loaded on the page&amp;nbsp;&lt;A href="https://developers.hubspot.com/global-form-events" target="_blank"&gt;https://developers.hubspot.com/global-form-events&lt;/A&gt;&lt;/P&gt;&lt;P&gt;If it's an embed code, use the onFormReady callback function in the embed code.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;If this answer helped, please, mark as solved &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;tim@belch.io | &lt;A href="https://forms.belch.io" target="_blank"&gt;forms.belch.io&lt;/A&gt; | Design your own Beautiful HubSpot Forms; No coding necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Drop by and say Hi to me &lt;A href="http://slack.belch.io/" target="_blank"&gt;on slack&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 17:55:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210518#M8750</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-10-05T17:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210540#M8753</link>
      <description>&lt;P&gt;tjoyce,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the speedy reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a form module in the Design Manager. I think that global from events is a step in the right&amp;nbsp;direction. Thank you for sending this my way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by 'wrap your code' do you essentially mean that the JS that I have written should use the eventListener mentioned (&lt;A href="https://developers.hubspot.com/global-form-events" target="_self"&gt;in the Hubspot Documentation&lt;/A&gt;) to instantiate the functions&amp;nbsp;that I have created? I am currently using the following code to wait until the entire DOM has loaded to enqueue my functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;window.onload = function() {
  setRealInputClasses();
  setPseudoInputClasses();
  initializeEventListeners();
};&lt;/PRE&gt;&lt;P&gt;I have a link shown below that will show you the exact issue that I am experiencing. Please let me know if you have any questions, if we work together I think we could very well solve this issue. Thank you!&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/16wQdWOs-Rdts8OO1_dir8OYgBAjTOjIb/view?usp=sharing" target="_self"&gt;Video of Issue&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:25:16 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210540#M8753</guid>
      <dc:creator>ben_groneman</dc:creator>
      <dc:date>2018-10-05T19:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210542#M8754</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72592"&gt;@ben_groneman&lt;/a&gt;&amp;nbsp;- Yes, you're right, call your function from the onFormready. Doing the window.onload won't quite cut it because the window isn't aware of the form that's pulling in through the ajax call.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:31:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210542#M8754</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-10-05T19:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210556#M8755</link>
      <description>&lt;P&gt;My apologies,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't believe that I am understanding what you mean by this. I have tried the following blocks of code, with no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;window.addEventListener('message', event =&amp;gt; {
   if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormReady') {&lt;BR /&gt;       setRealInputClasses();&lt;BR /&gt;       setPseudoInputClasses();&lt;BR /&gt;       initializeEventListeners();
       console.log("Form Submitted!");
   }
});&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;hbspt.forms.create({ 
    portalId: 'xxxxx',
    formId: 'aa8b5b4a-62ac-461b-a387-XXXXXXXXXXX',
    onFormReady($form, ctx){
      setRealInputClasses();
      setPseudoInputClasses();
      initializeEventListeners();
   	}
  });&lt;/PRE&gt;&lt;P&gt;The first code block I attempted did not go through because of the if statement would loop a few times, and continually return a false value.&lt;/P&gt;&lt;P&gt;The second code block would not register because 'forms' was undefined.&lt;/P&gt;&lt;P&gt;I am not sure where the disconnect here might be, but I feel as if I am not fully grasping why the form would be resetting the checkboxes based on a users event.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 20:39:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210556#M8755</guid>
      <dc:creator>ben_groneman</dc:creator>
      <dc:date>2018-10-05T20:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210662#M8763</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72592"&gt;@ben_groneman&lt;/a&gt;&amp;nbsp;- I'm not entirely sure what the root cause is but, you're trigger('change') is either not firing properly, or not bubbling propperly. If I change your code to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	switch (b)
	{
	case true:
		&lt;FONT color="#339966"&gt;&lt;STRONG&gt;a.click();&lt;/STRONG&gt;&lt;/FONT&gt;
		break;
	case false:
		a.prop("checked", false).change();
		break;
	case null:
		console.log("Something is awry the value of checked is: " + b)&lt;/PRE&gt;&lt;P&gt;simulating a click is working fine, but changing the prop manually does not. Maybe this will help you in debugging.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 12:44:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210662#M8763</guid>
      <dc:creator>tjoyce</dc:creator>
      <dc:date>2018-10-08T12:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hubpsot Form clearing check boxes when leveraging JavaScript</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210877#M8786</link>
      <description>&lt;P&gt;tjoyce,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for helping me debug this issue. Upon changing the action to be a click, and changing the window.onload&amp;nbsp;function, I was able to solve this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is greatly appreciated. I hope that others can benefit from this posting as well!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;~ B&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 15:13:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Hubpsot-Form-clearing-check-boxes-when-leveraging-JavaScript/m-p/210877#M8786</guid>
      <dc:creator>ben_groneman</dc:creator>
      <dc:date>2018-10-09T15:13:40Z</dc:date>
    </item>
  </channel>
</rss>

