Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
syedalamabbas opened this issue Mar 12, 2016 · 4 comments

Comments

@syedalamabbas
Copy link

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 ?

@jrfnl
Copy link
Collaborator

jrfnl commented Mar 12, 2016

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)

@wester97
Copy link

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' );

@ecosyse
Copy link

ecosyse commented May 5, 2018

@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.

@dackr
Copy link

dackr commented Aug 30, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants