The following code is supposed to modify the aesthetic and function of a submit button:
$('[data-image-upload-button]').click(function(){
if ($('[data-product-image-input]')[0].files.length > 0) {
$('[data-product-image-input]').remove()
$(this).prop('disabled', true)
$(this).text('Uploaded!')
$(this).removeClass('btn-outline-primary')
$(this).addClass('btn-outline-success')
}
})
However, when I click the button, this code executes, but the form does not submit. I intentionally didn't use preventDefault()
because I wanted the form to submit as well as for this js block to execute.
I tried triggering this function on a submit
event instead of click
, but that is producing an invalid_authenticity_token
error.
I also tried calling submit()
inside the function, but it isn't working properly due to the form being multipart.
What am I doing wrong?