Hey Elliot,
I tried it on a normal page using the normal editor and it rendered fine without adding in the extra tags … only seems to be when using the WYSIWYG field for the custom fields.
Thanks,
Steve
It is mb.miniAudioPlayer which is causing the problem.
No JS errors on page. Success AJAX callback function does indeed run. (Is there any way to print JS errors from the AJAX request url?)
Matched ID in JS acf/setup_fileds trigger to the $options[‘form_attributes’][‘id’] from when setting up form.
Ran code after HTML was returned as well as attempted a 5000 milisecond timeout function to double check. (Not really necessary since the HTMl is returned before the AJAX success callback function is run).
If you are familiar with Zurb Foundation, I am using this JS to return the HTML within the container DOM:
$(".reveal-popup-button").click(function(event) {
event.preventDefault();
$("#my-popup-container").foundation("reveal", "open", {
url: ajaxurl,
action: "my_popup_ajax",
type: "POST",
success: function(data) {
$(document).trigger("acf/setup_fields", $("#acf-ajax-form"));
},
error: function() {
}
});
});
And here is my WP AJAX action:
function my_popup_ajax_callback() {
echo "<div id="my-popup-content">";
$args = array(
"post_title" => "Draft",
"post_status" => "draft",
);
$id = wp_insert_post( $args );
$html = my_popup_build_acf_form( $id, 12 );
echo $html;
echo "</div>";
die();
}
add_action( "wp_ajax_my_popup_ajax", "my_popup_ajax_callback" );
And the function that returns the form’s HTML:
function my_popup_build_acf_form( $id, $fieldgroup ) {
$options = array(
"post_id" => $id,
"field_groups" => array( $fieldgroup ),
"form_attributes" => array(
"id" => "acf-ajax-form"
),
"return" => add_query_arg( "updated", "true", get_permalink( $id ) ),
"html_field_open" => "<div>",
"html_field_close" => "</div>",
"html_before_fields" => "",
"html_after_fields" => "",
"submit_value" => "Submit",
"updated_message" => "Post updated.",
);
ob_start();
acf_form( $options );
return ob_get_clean();
}
Did you get any JS errors in your console log?
Did you match the ID of the code to the ID of the form element?
Did you run this code after the new HTML had been returned?
Thank you for your response! That was my suspicion as well, however it seems that your suggestion is not working. I tried these two snippets within the success function of the AJAX request:
$(document).trigger('acf/setup_fields', $('#id-of-container'));
AND
$(document).trigger('acf/setup_fields', $('#id-of-acf-form'));
Neither of those worked… I will be honest and say that I would be considered a newbie at jQuery, so perhaps you could offer any more guidance? Of course we all thank you for the helpful support in these forums… it is definitely gracious and helpful.
Hi @drsolutions
Looks like your error is coming from a plugin called ‘tinymcemaplayerJs’ or something similar.
You will have to solve this error for ACF and WP to function correctly
Hi @tatemz
The problem is that the replacement HTML coming back from the AJAX is not recognized by ACF. This is why it is not styled correctly / interacts correctly.
You will need to re initialize the ACF javascript on the HTML. You can do this quite easily by running a jQuery action on the new DOM element like so:
$(document).trigger('acf/setup_fields', $('#new-element'));
Hi @Sour Mash Steve
Thanks for the quesiton. Can you please test the difference between a WYSIWYG field and the native the_content?
Do both values on the front end render the same? Or is ACF adding extra p tags?
Hi @Ailsa_C
I can confirm that the WYWSIWYG field is not intended to override the_content value. I suspect that your theme has some code that is taking this value and updating the post the_content with it.
Could this be the case?
For consistencies sake i’d probably just use two ACF wysiwyg fields. This of course does have it’s drawbacks, you can’t use the default the_content functions for starts and the_excerpt field doesn’t get created; but if you don’t need either of those then there’s no reason why using 2 ACF wysiwyg’s would be a problem.
Are you using a Wysiwyg field for a shortcode alone? Or is the field being used for content and shortcodes?
If it’s shortcode only, you could try changing your Wysiwyg field to a standard text field, then use the following PHP to activate the shortcode this way:
<?
$shortcode = get_field('my_shortcode');
echo do_shortcode($shortcode);
?>
Untested, but should work.
Hi @zsalwen
I think your issue is caused by using tinymce advanced to modify the wysiwyg toolbars.
This is overriding acf’s html toolbar button.
You should be able to add this button back into the toolbar via the plugin
For the record, there are no js errors on that page.
I’m experiencing the same issue, on a PC. I’ve tried using a number of different browsers (Chrome, IE, Firefox, Safari), but to no avail. I’m running version 4.1.8 of ACF, which does not seem to display any “HTML” button to view the source code. Please see attached screenshot.
SCRIPT5007: Unable to get property ‘id’ of undefined or null reference
tinymcemaplayerJs.php, line 27 character 17
Hi @drsolutions
Can you open up your console log and check the page for JS errors?
I think the client might be doing something wrong, I finally got around testing it on Mac And I cant reproduce it. Nothing is wrong.
I have a screenshot for you if that helps.
http://www.drsolutions.co.uk/acf/acf-problems.jpg
Further to the above, it seems to be where there is more than one WYSIWYG loading on the page. It is not repeater specific
Hi @scottnath
It is not possible for ACF to run the ‘the_content’ filter on it’s WYSIWYG values as it will cause massive issues such as:
1. A bbPress forum will render twice
2. A shopping cart will render twice
I would advise you to not modify the core functionality, but to just run the_content on the value you get back from the API.
That way, the code is within your theme, not within ACF.
You could even just use this filter in your functions.php file to always run the_content on all WYSIWYG values:
<?php
add_filter('acf/format_value_for_api/type=wysiwyg', 'format_value_for_api_wysiwyg', 10, 3);
function format_value_for_api_wysiwyg( $value, $post_id, $field )
{
$value = apply_filters( 'the_content', $value );
return $value;
}
?>
Hi @SMillerNL
Would you mind posting a screenshot of the issue?
Also, as this is the new support forum (currently in beta) I have a few questions for you if you don’t mind:
Thanks
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.