jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I tried to use cmb2 conditionals with frontend form editing of the snippet lib, and its not working.

syedalamabbas opened this issue · comments

Hi ,
I dont know what settings I am missing or is it dysfunctional in the way I want to use. I copied 'cmb2-conditionals.php' and 'cmb2-conditionals.php' in my theme folder. (I am not using this as a plugin). I place the following code in the 'cmb2-front-end-submit.php' :

/**
 * Get the cmb2 bootstrap
 */
if ( file_exists(  __DIR__ . '/cmb2/init.php' ) ) {
    require_once  __DIR__ . '/cmb2/init.php';
} elseif ( file_exists(  __DIR__ . '/CMB2/init.php' ) ) {
    require_once  __DIR__ . '/CMB2/init.php';
}
require_once 'cmb2-conditionals.php';

I include the fields in the given examples in my form, I can see the fields but no conditional logic is being displayed. Is this functionality supported with latest cmb2 version ?

You'll need to enqueue the CMB2-conditionals JS file. This is not done automatically for non-CPT pages.
There currently isn't a great way to do this other than enqueueing the script yourself (mind the path!):

wp_enqueue_script('cmb2-conditionals', plugins_url('/cmb2-conditionals.js', 'path/to/CMB2_conditionals/file'), array('jquery'), '1.0.2', true);

FYI: I have a PR in the works which will make this a lot easier.

(duplicate of #18)

commented

I resolved this by giving my content wrapper id="post". The init action of the conditionals javascript includes this target:

CMB2ConditionalsInit( '#post', '#post .cmb2-wrap' );

@wester97
Can't believe I overlooked that. Haha. Thank you my friend. Using id="post" for content/form div is what I needed....after enqueing js for specific page template with form.

Cheers.

hello friends please can you help me
it works well in the back end but in the front end I have not managed to load the script but the conditional field does not work.
please can you let us see how you have to do in the front end an example please?