Home › Forums › Front-end Issues › Not working scripts ACF logic
Hello!
After moving elements have stopped working scripts ACF logic. Move the item in the form:
$('.acf-field').appendTo('#category');
how to get the scripts to work?
p.s.: English is not the native language
<?php
/*
Template Name: ACF Form
*/
acf_form_head();
get_header();
acf_enqueue_uploader();
?>
<div class="acf-grid">
<div class="grid">
<div class="col-3" id='category'></div>
<div class="col-9 grid">
<div class="col-12 grid">
<div class="col-6" id='cat-box'></div>
<div class="col-6"></div>
</div>
<div class="col-12 grid">
<div class="col-6" id='adres'></div>
<div class="col-6" id='contacty'></div>
</div>
</div>
</div>
<div class="grid">
<div class="col-9" id='descriptions'></div>
<div class="col-3" id='add-file'></div>
</div>
</div>
<?php
$args = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'markers',
'post_status' => 'draft',
),
'post_title' => false,
'submit_value' => 'Создать',
'updated_message' => 'Ваша запись поставлена в очередь на модерацию'
);
acf_form( $args );
?>
<script type="text/javascript">
//$(document).ready(function() {
acf.add_action('ready', function( $el ){
$('.acf-grid').appendTo('.acf-form-fields');
$('.category').appendTo('#category');
$('.cat-box').appendTo('#cat-box');
$('.adres').appendTo('#adres');
$('.contacty').appendTo('#contacty');
$('.descriptions').appendTo('#descriptions');
$('.add-file').appendTo('#add-file');
});
//});
</script>
<?php get_footer(); ?>
ACF’s JavaScript is based on the elements where they are located. Most likely it stops working because ACF cannot find what it’s looking for or the actions that are attached to element are no longer attached because they do not appear where they are expected to be. Basically, you cannot alter the way that ACF outputs the HTML structure of the field group.
Yes, I understand that. conditional logic handler does not see the displaced elements.
is there a way to explicitly tell the handler to the elements?
No, If you’re going to move elements then you’ll need to write all your own JavaScript code to do what ACF should be doing.
You must be logged in to reply to this topic.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.