rails 中用于文件大小验证的咖啡脚本代码?
Coffee script code for file size validation in rails?
我曾尝试验证嵌套属性中附件的文件大小。但它不能正常工作。有人遇到过类似的问题吗?
字段计数大小是为了防止您有多个文件附件。您首先必须检查未隐藏文件的文件大小,然后向其添加错误消息。
$('.file-submit-button').click ->
fields_count = 0
$('.file-attachment').each ->
fields_count++
if this.files[0].size > 5 * 1000 * 1000 && $(this).closest('div[class=fields]').css('display') != 'none'
file_attachment_fields = document.querySelectorAll('.file-attachment')
file_attachment_fields[fields_count - 1].setCustomValidity('File size exceeds 5 MB')
file_attachment_fields[fields_count - 1].reportValidity()
else
file_attachment_fields = document.querySelectorAll('.file-attachment')
file_attachment_fields[fields_count - 1].setCustomValidity('')
我曾尝试验证嵌套属性中附件的文件大小。但它不能正常工作。有人遇到过类似的问题吗?
字段计数大小是为了防止您有多个文件附件。您首先必须检查未隐藏文件的文件大小,然后向其添加错误消息。
$('.file-submit-button').click ->
fields_count = 0
$('.file-attachment').each ->
fields_count++
if this.files[0].size > 5 * 1000 * 1000 && $(this).closest('div[class=fields]').css('display') != 'none'
file_attachment_fields = document.querySelectorAll('.file-attachment')
file_attachment_fields[fields_count - 1].setCustomValidity('File size exceeds 5 MB')
file_attachment_fields[fields_count - 1].reportValidity()
else
file_attachment_fields = document.querySelectorAll('.file-attachment')
file_attachment_fields[fields_count - 1].setCustomValidity('')