Home › Forums › Front-end Issues › initialize js
Hello,
I tryed coding a front end user post, and so far everithing went well.
However, i am stuck at initializing the JS, in order to make the conditional fields and map to work.
Can somebody please tell me what code do i need to add, and where? This JS code is way over me, and i do not know how to work with it.
Thank you for helping me!
If you’re using ACF 5 all you need to to for the necessary JS to load is to put this at the very top of the template file (above get_header())
<?php acf_form_head(); ?>
Hello Jonathan and thank you for trying to help me out.
I am using acf pro 5.0.8 and i did placed that code before the get_header.
However,the form gets displayed,but several fields are not working properly,like the map or the logical fields.
Please have a look at ecerkoop.nl/moto/vinde-moto
And this is the code i am using on that page template :
<?php
/**
* Template Name: Vinde Moto
*/
?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id=”page” class=”single”>
<article class=”<?php mts_article_class(); ?>”>
<div id=”content_box” >
<div id=”primary”>
<div id=”content” role=”main”>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php acf_form(array(
‘post_id’ => ‘new_post’,
‘post_title’ => true,
‘new_post’ => array(
‘post_type’ => ‘moto’,
‘post_status’ => ‘publish’
),
‘return’ => ‘/anunt-publicat’,
‘updated_message’ => __(“Post updated”, ‘acf’),
‘submit_value’ => ‘Listeaza’
)); ?>
<?php endwhile; ?>
</div><!– #content –>
</div><!– #primary –>
</div>
</article>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
No there’s no need for that 🙂
Your issue is actually not with ACF per se but rather that you have a JS error occurring early on the page resulting in all other JS not loading. Javascript is like PHP in the sense that if a fatal error occurs it stops all further rendering.
This code
jQuery.fn.exists = function(callback) {
var args = [].slice.call(arguments, 1);
if (this.length) {
callback.call(this, args);
}
return this;
};
causes this error:
Uncaught TypeError: Cannot read property ‘call’ of undefined
So it would seem like callback is undefined at that point in your javascript.
I will try to find andd remove that code, and then change the theme
I`ll let you know how things go.
Thank you for taking time to help me out.. you are awsome!
Oh and if you have any trouble finding the code snippet it’s at the very beginning of customscript.js found here: http://everkoop.nl/moto/wp-content/themes/schema/js/customscript.js?ver=4.2.3
You are right.
I just edited that file, removed that code and now it runs perfectly!
Thank you verry much for helping me out!
And for everibody else who is reading this, i am using schema theme, and the error was in /wp-content/themes/schema/js/customscript.js == i just deleted the first 7 lines.
Thank you again Jonathan!
No problem 🙂
But be careful since the code probably was there for a reason so you might want to check that all other functionality of your site is working without it 🙂
If not you might want to contact the theme author and notify them of the issue so that they can fix it in an update!
The topic ‘initialize js’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.