Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Create a new object for custom validation of a custom field.
var mySubmitController = Marionette.Object.extend( {
initialize: function() {
this.listenTo( Backbone.Radio.channel( 'forms' ), 'submit:response', this.actionSubmit );
},
actionSubmit: function( response ) {
// Do stuff here.
},
});
// On Document Ready...
jQuery( document ).ready( function( $ ) {
// Instantiate our custom field's controller, defined above.
new mySubmitController();
});
@kristjankoppel

This comment has been minimized.

Copy link

@kristjankoppel kristjankoppel commented May 25, 2017

I've tried this now on two different WordPress sites, and on a clean WP install and i get this error on console:
Uncaught ReferenceError: Marionette is not defined

Do anybody have any clue or idea what has changed?

@justinestrada

This comment has been minimized.

Copy link

@justinestrada justinestrada commented Feb 26, 2018

I get the same error

@thpapag

This comment has been minimized.

Copy link

@thpapag thpapag commented Apr 23, 2018

Any news on this error?

@michealjroberts

This comment has been minimized.

Copy link

@michealjroberts michealjroberts commented Sep 24, 2018

You likely have included your script before the <?php wp_footer(); ?> tag in your footer.php template - you need to include it after this tag (i.e., after the Marionette object has been injected by Ninja Forms).

@geertvdheide1

This comment has been minimized.

Copy link

@geertvdheide1 geertvdheide1 commented Nov 5, 2018

You likely have included your script before the <?php wp_footer(); ?> tag in your footer.php template - you need to include it after this tag (i.e., after the Marionette object has been injected by Ninja Forms).

Adding to this: even if you've added your custom script that holds this gist in the proper way - meaning through wp_enqueue_script and wp_footer - the error may still show up. It's important to have your custom script be included after any dependencies, and Wordpress allows us to set this up like so:

wp_enqueue_script( 'my-custom-scripts', get_template_directory_uri() . "/my-folder/my-script.js", array('jquery', 'nf-front-end'), false, true );

This assures your custom script runs after 'nf-front-end', which in turn depends on 'nf-front-end-deps' which contains Marionette. Including your custom script like this makes sure the code runs after both Backbone and Marionette are loaded, solving the issue.

@gauravblaggan

This comment has been minimized.

Copy link

@gauravblaggan gauravblaggan commented Feb 20, 2019

Add your code inside this form ready function because once the form is loaded then the error will be solved
jQuery(document).on( 'nfFormReady', function( e, layoutView ) {
Add your code here...
});

@dbloomsday

This comment has been minimized.

Copy link

@dbloomsday dbloomsday commented Aug 21, 2019

You can simply move all of the code below "jQuery( document ).ready( function( $ ) {" and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment