Skip Navigation

[Resolved] I need a little JS View Help

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 3 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#528920

I am trying to: Create a View the Loops and generates a Bootstrap Modal Button, with pop up.

I am using the following code:

<h3 class="text-center">[wpv-post-link]</h3>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal-[wpv-post-id]">
Book An Appointment Online
</button>

<!-- Modal -->
<div class="modal fade" id="myModal-[wpv-post-id]" tabindex="-1" role="dialog" aria-labelledby="myModalLabel-[wpv-post-id]">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Appointment Request</h4>
      </div>
      <div class="modal-body">
      <script type="text/javascript">
      d3cp_bid = '[types field='demandforcebusinessid'][/types]'; // Business ID in DemandforceD3
      d3cp_appt_source = 'VFC Website';  //Optional. See Instructions.
      d3cp_appt_returnpage = '/appointment-request-complete'; //Optional. See Instructions.
      </script>
      <script src="//local.demandforce.com/b/[types field='demandforcescriptslug'][/types]/scheduler.widget" type="text/javascript"></script>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      </div>
    </div>
  </div>
</div>

This works in terms of creating a button and modal pop up, however only the first pop up contain the correct content.

The sequential pop up result in a 404.

Also, the code above generates multiple JQuery Migrates in my console.

I believe the Javascript should be moved to the JS section of the View Loop, but I have been unsuccessful in making that work as well.

Thoughts?

Thanks!

#528984

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Brandon,

Thank you for contacting our support forum.

Could you explain a bit what this code is trying to do ? so I can assist better

Also shortcodes don't work inside Javascript since Javascript is process on the frontend. Shortcodes are processed by PHP which occurs on the server side.

Thanks,
Shane

#528998

I am simply running through a loop, populating a Modal window with data from my custom field type.

#529788

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Brandon,

I'm not sure why you would need javascript to do this since bootstrap already provides the modal output.

All you need to do is add the shortcode to the modal within the <div class="modal-body"> tag.

Your content should show up normally like this.

Here is an example.

<h3 class="text-center">[wpv-post-link]</h3>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal-[wpv-post-id]">
Book An Appointment Online
</button>
 
<!-- Modal -->
<div class="modal fade" id="myModal-[wpv-post-id]" tabindex="-1" role="dialog" aria-labelledby="myModalLabel-[wpv-post-id]">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Appointment Request</h4>
      </div>
      <div class="modal-body">
      [types field='demandforcebusinessid'][/types]
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      </div>
    </div>
  </div>
</div>

Please let me know if this helps.
Thanks,
Shane

#530494

OK, so creating the Modal is not the issue, but the unique Javascript that I need to load inside of each Modal seems to be the issue.

Here is what needs to go into the Modal body:

<div class="modal-body">
      <script type="text/javascript">
      d3cp_bid = '[types field='demandforcebusinessid'][/types]'; // Business ID in DemandforceD3
      d3cp_appt_source = 'VFC Website';  //Optional. See Instructions.
      d3cp_appt_returnpage = '/appointment-request-complete'; //Optional. See Instructions.
      </script>
      <script src="//local.demandforce.com/b/[types field='demandforcescriptslug'][/types]/scheduler.widget" type="text/javascript"></script>
      </div>

Thoughts?

#530528

Hi, Shane is out today so I'll take over this ticket. I hope that's okay with you. I think I see what you're trying to do here, but I'm not quite clear. Should the script tags for each modal element be in the source code of your page on page load, or should they be inserted into the DOM dynamically when each modal is opened?

It appears to me that you're trying to trigger some tracking code when someone opens a modal, but instead all the code is included directly in the page. This will result in your tracking events all firing on page load, instead of waiting until the modal is opened. Can you explain in a bit more detail for me?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.