The user has the option to perform several actions in the form, after action when he submits the form, needs to add a JavaScript object to form. I tried multiple ways, in server data reached as [Object object]
JavaScript Object
var damageitems = {'5b3b43285d57025915000002':
{action: "accept",damage_location_name:"Front Bumper", estimated_total_repair_cost: "993.72", estimated_total_repair_cost_currency:"USD"}
}
Script I tried
$( "form" ).submit(function( event ) {
event.preventDefault();
url = $(this).attr( "action" );
var postData = $(this).serializeArray();
postData.push({name: 'damage_items', value: damage_items});
$.post(url, postData, function(){});
});
Value reached in server
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"uztc+G0fyTb8wH7D6HZAslTfxuJvFLP3UunjiRjWylk=", "damage_items"=>"[object Object]", "action"=>"batch_update", "controller"=>"damage_items", "claim_id"=>"5b3b41415d57026665000001"}
My aims submit the value as normal submit not ajax,
the value in js variable reaches in the server as a hash with key damage_items
.
Not prefer the way add it in form control value then submit