<?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 Re: Embed code: how to write  a validation message? in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537549#M49255</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I fixed the &lt;SPAN&gt;preventDefault() issue; I added into&amp;nbsp;onFormReady the click event:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;onFormReady: function($form) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var pp=$form.find('input[type=submit]');&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;pp.on('click', function(e) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;e.preventDefault();&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;return false;&lt;/STRONG&gt;&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 20:24:52 GMT</pubDate>
    <dc:creator>GBulleri</dc:creator>
    <dc:date>2021-12-06T20:24:52Z</dc:date>
    <item>
      <title>Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/536823#M49214</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I' am working with the embed code.&lt;/P&gt;&lt;P&gt;The Hubspot documentation says&amp;nbsp; to wrire custom code inside onFormSubmit&lt;/P&gt;&lt;PRE&gt;hbspt.forms.create({
      portalId: '',
      formId: '',
      onFormSubmit: function($form) {
        // YOUR SCRIPT HERE
        } 
});       &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to programmatically write&amp;nbsp; by jquery/javascript a validation error or&amp;nbsp; a message&amp;nbsp; like for&amp;nbsp; example "email must be formatted correctly"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GBulleri_0-1638708807102.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/55074i0401E2A2DE34B77F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GBulleri_0-1638708807102.png" alt="GBulleri_0-1638708807102.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Dec 2021 12:55:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/536823#M49214</guid>
      <dc:creator>GBulleri</dc:creator>
      <dc:date>2021-12-05T12:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537089#M49220</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/267611"&gt;@GBulleri&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Are you using a custom property or a default property?&lt;BR /&gt;If it is the default email property then HubSpot will give an error that you can customize with some JavaScript.&lt;BR /&gt;If it is a custom property, you need to write your own validation code.&lt;BR /&gt;&lt;BR /&gt;Please let me know!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 07:29:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537089#M49220</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2021-12-06T07:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537100#M49222</link>
      <description>&lt;P&gt;Thank you... but the issue is:&lt;/P&gt;&lt;P&gt;suppose that theuser write 7 characters in a field and the validation rule is "do not write more than 5 characters" .I want to inform the user that he must write&amp;nbsp; max 5 characters.&lt;/P&gt;&lt;P&gt;Which is the jquery instruction to write the info "please write maxt 5 characters"&lt;/P&gt;&lt;P&gt;in the same area&amp;nbsp; of the screen where usually hubspot write his own messages? (just below the input field as show in image of my t post)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 08:27:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537100#M49222</guid>
      <dc:creator>GBulleri</dc:creator>
      <dc:date>2021-12-06T08:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537105#M49223</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/267611"&gt;@GBulleri&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;You could do something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;window.addEventListener('message', event =&amp;gt; {
  if (event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormReady') {
     const input = document.querySelector('input[name="property"]') // Change this to the property you want to validate
     // Error message
     const error = document.createElement('div')
     error.setAttribute('class', 'form-error-message')

     input.addEventListener('input', e =&amp;gt; {
       if (e.currentTarget.value.length &amp;gt; 5) {
         // Time to display an error
         input.parentElement.appendChild(error)
       }
     })
  }
})
&lt;/LI-CODE&gt;
&lt;P&gt;You would still need to use the 'onFormSubmit' event to prevent the form from submitting if this is unvalid.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 08:55:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537105#M49223</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2021-12-06T08:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537425#M49242</link>
      <description>&lt;P&gt;Thank You very Much! Exactly what I need.&lt;/P&gt;&lt;P&gt;I will implement as soon as possible&amp;nbsp; your suggestion and then I will let you know how things are going&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 17:45:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537425#M49242</guid>
      <dc:creator>GBulleri</dc:creator>
      <dc:date>2021-12-06T17:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537504#M49253</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your suggestion was precious, I did small modifications in bold:&lt;/P&gt;&lt;P&gt;onFormReady: function($form) {&lt;BR /&gt;window.addEventListener('message', event =&amp;gt; {&lt;BR /&gt;if (event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormReady') {&lt;BR /&gt;const input =&lt;STRONG&gt;$form.find&lt;/STRONG&gt;('input[name="firstname"]');// document.querySelector('input[name="firstname"]') // Change this to the property you want to validate&lt;BR /&gt;// Error message&lt;BR /&gt;const error = document.createElement('div')&lt;BR /&gt;error.setAttribute('class', 'form-error-message')&lt;BR /&gt;error.innerHTML='error';&lt;BR /&gt;&lt;STRONG&gt;input[0]&lt;/STRONG&gt;.addEventListener('input', e =&amp;gt; {&lt;BR /&gt;if (e.currentTarget.value.length &amp;gt; 5) {&lt;BR /&gt;// Time to display an error&lt;BR /&gt;&lt;STRONG&gt;input[0]&lt;/STRONG&gt;.parentElement.appendChild(error)&lt;BR /&gt;}&lt;BR /&gt;})&lt;BR /&gt;}&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the last issue I have is&amp;nbsp; where to put&amp;nbsp; preventDefault(), please look at bold comment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;onFormReady: function($form) {&lt;BR /&gt;window.addEventListener('message', event =&amp;gt; {&lt;BR /&gt;event.preventDefault();&amp;nbsp;&lt;STRONG&gt; --&amp;gt; the form is still submitted&lt;/STRONG&gt;&lt;BR /&gt;return false;&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You very much for your support&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:21:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537504#M49253</guid>
      <dc:creator>GBulleri</dc:creator>
      <dc:date>2021-12-06T19:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537549#M49255</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I fixed the &lt;SPAN&gt;preventDefault() issue; I added into&amp;nbsp;onFormReady the click event:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;onFormReady: function($form) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var pp=$form.find('input[type=submit]');&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;pp.on('click', function(e) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;e.preventDefault();&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;return false;&lt;/STRONG&gt;&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:24:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/537549#M49255</guid>
      <dc:creator>GBulleri</dc:creator>
      <dc:date>2021-12-06T20:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Embed code: how to write  a validation message?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/538233#M49274</link>
      <description>&lt;P&gt;Awesome&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/267611"&gt;@GBulleri&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the updates!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 18:22:39 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Embed-code-how-to-write-a-validation-message/m-p/538233#M49274</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2021-12-07T18:22:39Z</dc:date>
    </item>
  </channel>
</rss>

