Support

Account

Home Forums Front-end Issues Detect if a field is changed?

Solved

Detect if a field is changed?

  • I’ve setup a front end form with a lot of fields with acf_form().

    Now I need to know if any of the (many) fields are changed without saving.
    I want to enable a special button which is only active when all fields are savedform is submitted.

    Is there any way to detect/know this?

  • You can do this with Javascript by listening to the “change” event. jQuery also provides a method, like:

    $('.field-class').change(function(e){
        //Do stuff on field change
    });

    Note that this event provides a basic change event for input fields and you need more for other types of fields, or if you want your button to show immediately when someone starts typing. You can check out this thread on Stackoverflow: http://stackoverflow.com/questions/6458840/on-input-change-event

  • Thanks, I should have thought of that myself 🙂

  • Hi,

    I am messing with ACF and some JS to make calculations based on my inputs. I struggle with the switch fields.

    Basically I need to detect if a switch input is on and make a different calculation if it is. For now I rely on checking the parent of the input which receives a “-on” class when turned on, but that’s about it.

    The problem is that by firing the function on “change”, the calculation gets made first and then the switch input gets the class on. Is there a way to change the priority of my function, so that it fires right after the other Jquery functions that add the class “-on”?

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

The topic ‘Detect if a field is changed?’ is closed to new replies.