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

Uncaught TypeError: $ is not a function #36

Open
davetbo opened this issue Apr 16, 2017 · 1 comment
Open

Uncaught TypeError: $ is not a function #36

davetbo opened this issue Apr 16, 2017 · 1 comment

Comments

@davetbo
Copy link

davetbo commented Apr 16, 2017

Hello,

I just started using Zebra_Forms. I'm using it in Wordpress and I've installed it via composer by adding:

{
	"require": {
	  "stefangabos/zebra_form" : "*"
	}
}

to my composer.json. So far I have just done this test form:

        $this->form = new \Zebra_Form(get_class());
        $this->form->add('label','label_al_setup_street_address', 'al_setup_street_address', 'Street Address: * ');
        $this->form->add('text', 'al_setup_street_address', '');

and rendered it. I see this:
image

So far so good. However, in my console I see this:
image
and this:
image

That part of the javascript code was added by your library. Everywhere I refer to jQuery I actually spell out jQuery. I don't use $.

Also, I included your javascript by doing this:
add_action('admin_enqueue_scripts', array($this, 'generate_styles'));
and then later in the generate_styles function:
wp_enqueue_script('zebra_forms_js', WZ_PLUGIN_URL . 'vendor/stefangabos/zebra_form/public/javascript/zebra_form.js', array('jquery'));
so it should have the required jquery libraries accessible since I listed them as a dependency.

Any advice on how to get this to work? I'd rather not have to edit your javascript directly.

Best,
Dave

@davetbo
Copy link
Author

davetbo commented Apr 16, 2017

I just thought of one workaround, but it seems likely to be unsafe. If I do this it seems to fix the error in this instance, but I could see this kind of fix leading to unexpected problems:

$html = $this->form->render();
$target = preg_quote("$");
$html = preg_replace("/$target/", 'jQuery', $html, -1, $count);

Thoughts? I really appreciate your help. Also, this is going into a SaaS offering so if I end up using this long term I would be willing to donate to develop a closer support relationship going forward.

Best,
Dave

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

1 participant