Event on change to custom fields?

I can't work out what the event is that I need to hook into to catch changes to custom fields. I assumed the render.done event was what I needed but after debugging I can see it's not.

Basically, I need to dynamically update my Terms Of Service link with parameters that include the latest cart prices and quantities as well as my custom fields. I have no problem adding parameters to the TOS URL, it's just my custom fields that are a problem. When I enter the custom field details I can't get them to get added as parameters to the TOS URL.

So what event do I need to catch any changes to custom fields?
Comments
  • fc_adamfc_adam FoxyCart Team
    @timothyjl,

    Good question. For capturing changes to specific fields, your best bet would be to lean on native javascript or jQuery to handle that.

    As an example, with jQuery - assuming you had the following custom text input:
    <input type="text" name="my_custom_field" id="my_custom_field" value="" />
    You could have the following javascript in your store's custom footer in the configuration in the FoxyCart administration:
    <script>
    $(document).ready(function() {
    $("body").on("change", "#my_custom_field", function() {
    // Handle the change event
    });
    });
    </script>
    Assuming you already have a javascript function you're using to update the link - you could also just call that directly as the callback function:
    <script>
    $(document).ready(function() {
    $("body").on("change", "#my_custom_field", myUpdateFunction);
    });
    </script>
    I hope that helps!
  • @fc_adam.

    Useful feedback, I'll try it. But is there any reason why it can't be just like all the other checkout or cart events? It would be far better and more consistent if I could just add the necessary render.done or update.done event that picked up any change to the custom fields, just the same as I'd pick up the event for any changes to the cart quantities while in the checkout.
  • fc_adamfc_adam FoxyCart Team
    edited January 11
    Sorry for the delay in replying here - I've just gotten back from some travel.
    But is there any reason why it can't be just like all the other checkout or cart events? It would be far better and more consistent if I could just add the necessary render.done or update.done event that picked up any change to the custom fields, just the same as I'd pick up the event for any changes to the cart quantities while in the checkout.
    For what it's worth - the jQuery change event I listed is essentially how our native events are triggered too, so they aren't really that different from each other. If you wanted to apply it to all custom fields with a single call - you could apply a common class between them and use that as the identifier in the jQuery call instead of the #my_custom_field in my example.

    I'll follow-up privately about the code you whispered with some more details there.
Sign In or Register to comment.