Home Forums Backend Issues (wp-admin) Changing Field values with jquery gets ignored.


Changing Field values with jquery gets ignored.

  • I am currently working on a new field module for ACF, and I’m running into a really aggravating issue. Here’s a sample of my code:

    function render_field_settings( $field ) {
    			 $field, array(
    				'label'			=> 'Select ',
    				'instructions'	=> __('Select ','acf-i_am_a_name'),
    				'type'			=> 'hidden',
    				'name'			=> 'i_am_a_name_base',
    				'class'			=> 'acf-i_am_a_name parent_container',
    			 $field, array(
    				'label'			=> __('Extension Filter','acf-i_am_a_name'),
    				'instructions'	=> __('To show only certain  something, enter a comma separated list here.)','acf-i_am_a_name'),
    				'type'			=> 'text',
    				'name'			=> 'something_filter',
    				'class'			=> 'acf-i_am_a_name',

    Now what I do, is do something like


    With jquery to change the fields value.

    Oddly enough, I can only get the field to change if I do

    $('.i_am_a_name_base').attr('value', some_val); 

    The issue is, I CAN get the field value to change, however as soon as I hit save the change is gone. However, and this is the wierd part, if I change it with jquery and then ALSO update another field the jquery change also sticks.

    I took a look at event binds in the dom, and realized that on text field on change events were firing an event that updated the “_acfchanged” in the acf-form-data hidden section.

    I tried manually changing that field as well, but the changes still do not stick.

  • After changing the value try doing this,


    Not sure it will help.

  • Wow, that worked! I can’t believe I didn’t think to try that. I am seriously in your debt sir 🙂

  • Triggering the change event makes ACF update the _acfchanged you mentioned and may have other effects that I’m not aware of. It was really just a guess, but I’ve been working on projects where I’m extending the ACF JS and where I need to trigger change events after changing values in order to trigger ACF up update conditional logic in fields that also need to be updated because of my changes.

    This JS file has a bunch of “experiments” that I’ve done with extending the ACF JS functions. Linking to it because it has a lot of things in it that can help others that might be looking for information on how to do things in ACF using jQuery.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.