Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom jQuery not working on Wordpress Ninja Forms plugin

I am having some problems when I want to add custom jQuery code that affects the form.

For example when someone clicks an input or radio button another input or element to be hidden or shown.I tried to get a result like console.log('trigger'); when clicked or something else but nothing in dev. console appeared.Also, I tried the following methods:

To call the click event with .on('click', function()... or to call the event with .trigger('click');, or to change the event to change

To embed the script within a file from ninja forms or to put it inside the page at the ending of body tag in footer.php

To change the opening declaration of jQuery to work inside a function like this : (function($) {$(document).ready(function(){.....

I know that I could try another plugin, I tried one and the custom jQuery works but I really like this one and don't know why this is happening ...

Thanks

like image 779
Philipos D. Avatar asked Nov 29 '16 21:11

Philipos D.


People also ask

Why is Ninja Forms not sending email?

But often when users find Ninja Forms emails not sending, what's happening behind the scenes is that emails are rejected by a mail server on their way to your mailbox. WordPress uses the wp_mail() function, which can't authenticate emails. That's why servers silently reject them as spam.

How do I style a ninja in WordPress?

However, if you want to make changes to the individual form, navigate to your Ninja Forms Dashboard and select the form you wish to make the font customizations. Select the specific form field and open the Style settings > Label Styles > Font Size. Here, you can also change the color of the text, and more.

How do I add Captcha to ninja?

Navigate to Ninja Forms > Settings > Advanced Settings and look for the section titled reCaptcha Settings. This is where you will paste in the key and secret you copied to your clipboard in step one. Add the ReCaptcha v3 Site Key and reCaptcha v3 Secret Key credentials to their corresponding fields.


1 Answers

Not sure if you need help with this any more as it's been some time since you posted your question, but this may help others in the future. I had the same/similar issue with not being able to run JS/jQuery on the Ninja Forms and found that it's because Ninja Forms load their forms asynchronously. So, when your document.ready function runs, the form doesn't yet exist and it's not able to bind.

Ninja Forms have their own event ready state that can be used as follows:

jQuery(document).on( 'nfFormReady', function( e, layoutView ) {
    // Your code goes here...
});
like image 180
Mat Avatar answered Oct 26 '22 13:10

Mat