Story#113524121 - validate in web max file

This commit is contained in:
Vladimir Krylov 2016-03-07 12:00:23 +02:00
parent 6f4ff0fd46
commit cf3fce8055
4 changed files with 15 additions and 30 deletions

View file

@ -27,3 +27,17 @@ $(document).on 'page:change', ->
form.find('.js-ident-tip').show()
$('.js-contact-form').trigger('restoreDefault')
$('[data-legal_document]').each (e)->
fileInput = $(e.target)
minSize = 1 * 1024 # 100kB
maxSize = 8 * 1024 * 1024; # 8 MB
fileInput.parent('form').submit (e) ->
if (files = fileInput.get(0).files).length
fileSize = files[0].size
if fileSize < minSize
alert 'Document size is less then 100kB bytes'
return false
else if fileSize < maxSize
alert 'Document size is more then 8MB bytes'
return false

View file

@ -21,18 +21,3 @@
= button_tag t(:save), class: 'btn btn-warning'
- else
= button_tag t(:create), class: 'btn btn-warning'
:javascript
$(function(){
var fileInput = $('#depp_contact_legal_document');
var minSize = '1000';
$('form').submit(function(e){
if(fileInput.get(0).files.length){
var fileSize = fileInput.get(0).files[0].size;
if(fileSize < minSize){
alert('Document size is less then' + minSize + ' bytes');
return false;
}
}
})
})

View file

@ -10,4 +10,4 @@
= f.label :legal_document, t(:legal_document)
%p.help-block= t(:legal_document_max_size)
.col-md-7
= f.file_field :legal_document, :value => ''
= f.file_field :legal_document, :value => '', data: {legal_document: true}

View file

@ -32,17 +32,3 @@
$(function () {
$('#tabs a:first').tab('show')
})
$(function(){
var fileInput = $('#domain_legal_document');
var minSize = '1000';
$('form').submit(function(e){
if(fileInput.get(0).files.length){
var fileSize = fileInput.get(0).files[0].size;
if(fileSize < minSize){
alert('Document size is less then' + minSize + ' bytes');
return false;
}
}
})
})