form serialization in ajax call doesn't pull newest form data

form serialization in ajax call doesn't pull newest form data

GoddardGoddard Posts: 14Questions: 6Answers: 0
edited November 2019 in Free community support

I am trying to send my form data and I have an ajax reload function call in an onchange function for my form.

When I trigger the reload though it doesn't rebuild the jquery form serialization. Anyone know why?

I am sure jquery has a way to do this, but I must be doing it wrong.

currently it looks like this
$.fn.getFormValues = function getFormValues() {
return $('#filter-form').serializeArray().reduce((obj, field) => ({...obj, [field.name]: field.value}), {});
}

and inside my ajax config values I have
ajax {
data : $.fn.getFormValues()
}

In my onchange function which is triggered by form changes I can use console.log to see that the form values are indeed changed, but when the request is sent my datatable it isn't using the changed data. It is using the old data.

Answers

  • GoddardGoddard Posts: 14Questions: 6Answers: 0

    I figured it out.

    Need to wrap the pull in a function.

    data : function getvalues() {
    return $('#filter-form').serializeArray().reduce((obj, field) => ({...obj, [field.name]: field.value}), {});
    }

This discussion has been closed.