Closed KonstantinObuhov closed 6 years ago
I've made investigation and figure some problems out on line https://github.com/octobercms/october/blob/cfd3d543162d302ccac88b3227b7fd69195bc575/modules/system/assets/js/framework.js#L82 any custom data will be converted from an array of objects to an object of objects.
For example data in ajax request like this:
$(document).ready(function(){
getSelects = function() {
return $('.value-review select');
};
$selects = getSelects();
$selects.on('change', function(e) {
$selectValues = getSelects().serializeArray();
console.log($selectValues);
$.request('onUpdateFinalValue', {
data: $selectValues
});
});
});
For correct working it must be an array of objects http://api.jquery.com/jquery.param/ (If the object passed is in an Array, it must be an array of objects in the format returned by .serializeArray())
For working code above. We need to pass all data to data property as json object. I convert my data to json object with $.map. It works fine.
formData = function($el) {
var $form = $el.closest('form'),
formData = {};
if ($form.length > 0) {
var formDataS = $form.serializeArray();
$.map(formDataS, function(n, i){
formData[n['name']] = n['value'];
});
return formData;
}
};
Expected behavior
419 This solution works fine. Here is a request log when I updated Location model. http://clip2net.com/s/3N65PYE
Actual behavior
420 It doesn't work because the request looks like this. http://clip2net.com/s/3N663IT
Reproduce steps
I have my own custom formwidget that called "Mapbox" in my plugin what let me to create the location point for each object if I want.
_mapfields.htm
_mapbox.htm
MapBox.php
Model Location.php
October build
420
Why it may be wrong?