I am using the filter: gform_file_upload_markup
to modify the markup displayed when an image uploaded. However the issue is:
Load form for the first time, upload an image - the filter runs and changes the markup which is output - correct and working.
If the form is submitted, fails for whatever reason (you’ve missed an input), the images are still attached to the form which is great, however the markup is not the custom markup anymore, because those filters only run when you hit the file-upload and select an image. Therefore, what I have displayed is just the image filename.png for example.
Screenshot 1 - the form failed, page reloaded. Images are still technically attached to the form but the gform_file_upload_markup
did not run, so the default markup is used instead:
Code: this is the markup which is used when an image is uploaded. This does not run when the form fails and page is reloaded. Seems normal but just wanted to try get it to do so.
// This function will render the uploaded image in a dynamically generated <img> tag to preview to the user.
gform.addFilter('gform_file_upload_markup', function (html, file, up, strings) {
var tmpPath = 'https://s3-eu-west-2.amazonaws.com/example-media/uploads/gravity_forms/'+ path +'/tmp/';
var formId = up.settings.multipart_params.form_id,
fieldId = up.settings.multipart_params.field_id;
var fileName = up.settings.multipart_params.gform_unique_id + '_input_' + fieldId +'_'+ file.target_name;
html = "<div class='dynamic-image__item' style='background-image:url(" + tmpPath + fileName + ");' onclick='gformDeleteUploadedFile(" + formId + "," + fieldId + ", this);'><span class='dynamic-image__close-cta' alt='" + strings.delete_file + "' title='" + strings.delete_file + "'></span></div>";
return html;
});