Zebra_Form
Zebra_Form copied to clipboard
Uncaught TypeError: $ is not a function
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:
So far so good. However, in my console I see this:
and this:
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
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