Open rbaugh opened 4 years ago
@rbaugh, I'm having the same issue but I'm new to this plugin so a bit lost. Where (what file, etc.) should I add your code?
@rgilman The file I edited was below: https://github.com/mecachisenros/cf-civicrm/blob/master/fields/civicrm_state/field.php
The two lines I adjusted were lines 33 & 88. In the code above you will see the two lines I commented out at the beginning and end and then the two lines I added in as a replacement.
Line 33
( function( $ ) {
//jQuery( document ).ready( function( $ ) {
Line 88
//} );
})(jQuery);
Got it. Thanks!
Describe the bug I used the "CiviCRM Contact and Address" form template to create a quick test form. When loading up the form on the CF preview option or added as shortcode to a blank page, the cf.form.init trigger doesn't ever seem to kick in. I added an alert script to the
$( document ).on( 'cf.form.init cf.add', function( e, data ) {
script and could not get it to fire. I then changed the code around slightly to remove thejQuery(document).ready( function( $ ) {
wrapper and this seems to allow the code to execute.To Reproduce Steps to reproduce the behavior:
Expected behavior Expect the state field to refresh itself and use the default value from the country field to filter out the list of states to selected country.
I adjusted the code on the state field and this below is working.
Other Note When I initially tested this, it was on a fairly clean install of WP and CiviCRM. I was using the TwentyTwenty theme and when testing the form, it was initially erroring out on this code stating jQuery wasn't defined. So I switched over to a theme we are working on which I forced jQuery to load in the head and this fixed the issue.
Seems that the code could be setup and instead of just echoing inside the form, it could be added with
wp_add_inline_script( Caldera_Forms_Render_Assets::field_script_to_localize_slug(), $script_template );
which would add it in the footer with the rest of the CF scripts and makes sure that jQuery is loaded on the page.