Different field name for asynchronous upload and full form file field.
Different field name for asynchronous upload and full form file field.
I have two tables with two APIs.
Order
:
- customer_name
(text)
- customer_file
(ForeignKey reference to an Uploaded_file
's primary key)
Uploaded_file
:
- file_object
(file upload field)
I use an upload field with an AJAX object to upload the file to the Uploaded_file
table:
{
label: "file_object",
name: "file_object",
type: "upload",
display: function ( file_id ) {
console.log("File ID: " + file_id)
return '<img src="'+editor.file( 'file_object', file_id ).web_path+'"/>';
},
clearText: "Clear",
noImageText: 'No image',
ajax: {
'url': "/api/Uploaded_file_rest/"
headers: { 'X-CSRFToken': ... }
}
}
This allows me to upload the file asynchronously. I can see in my DB that the Uploaded_file
table has added an appropriate row. However, when I submit the full form, I get an error. It's trying to write the PK returned for the Uploaded_file
to the Order
's field name file_object
which doesn't work, because it's called customer_file
in the order table.
Is there a way to use a different field name for the uploaded_file
table and the Order
table?
This question has an accepted answers - jump to answer
Answers
If I'm understanding correctly, are you using the
uploadField
parameter in your/api/Uploaded_file_rest/
controller? That is the field name that Editor uses to tell the server what field is being uploaded for theupload
action.If correct, then change the
name
parameter for the object to what you want the main form to submit (customer_file
in this case) and usepreUpload
to modify the data being sent as part of the upload action (specifically set theuploadField
parameter's value on theajaxData
parameter).Regards,
Allan
Thanks, Allan. I had a workaround that was good enough for the time being and didn't want to muck with it until I had to. I came back to this to solve a different issue I was having. Works great!