form serialization in ajax call doesn't pull newest form data
form serialization in ajax call doesn't pull newest form data
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
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}), {});
}