TL:DR I am attempting to retrieve the value of the image_description field using JavaScript to include it in my post XHR request
Original query:
I am utilizing the file_picker_callback type image
I have enabled the image_description input field in my
tinymce.init({
....,
image_description: true,
...
Everything is uploading correctly, but I want to send the image_description field to store in the DB as well. However, I am having difficulty retrieving the data
Below are the two functions, directly from the tinymce website:
file_picker_callback: function(cb, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function() {
console.log(this.files);
var file = this.files[0];
console.log( meta ); //I thought it might be here in the meta bt it isn't
console.log( $('#mceu_62').val() ); //I tried to get it from its id but it returns undefined i think that field is created after this function is created.
var id = file.name;
var blobCache = tinymce.activeEditor.editorUpload.blobCache;
var blobInfo = blobCache.create(id, file);
blobCache.add(blobInfo);
// call the callback and populate the Title field with the file name
cb(blobInfo.blobUri(), { title: file.name });
};
input.click();
},
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', '/articles/postAcceptor');
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
failure('Invalid JSON: ' + xhr.responseText);
return;
}
success(json.location);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
formData.append('description', /*but i can't get the value*/);
xhr.send(formData);
}
@Karl Morrisons