mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 21:49:04 +01:00
Fix Admin forms behavior with input[type=files]
* Changes in file inputs are now detected when leaving the page * Text of file input labels is now restored when removing files
This commit is contained in:
parent
330d8ed3cc
commit
70e143bfa2
21
admin/assets/js/app.js
Normal file → Executable file
21
admin/assets/js/app.js
Normal file → Executable file
@ -206,6 +206,14 @@ Formwork.Form = function(form) {
|
||||
});
|
||||
|
||||
function hasChanged() {
|
||||
var $fileInputs = $form.find(':file');
|
||||
if ($fileInputs.length > 0) {
|
||||
for (var i = 0; i < $fileInputs.length; i++) {
|
||||
if ($fileInputs[i].files.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $form.serialize() != $form.data('original-data');
|
||||
}
|
||||
};
|
||||
@ -229,10 +237,17 @@ Formwork.Forms = {
|
||||
$target.change();
|
||||
});
|
||||
|
||||
$('input:file').change(function() {
|
||||
var files = $(this).prop('files');
|
||||
$('input:file').each(function() {
|
||||
var $this = $(this);
|
||||
var labelHTML = $('label[for="' + $(this).attr('id') + '"] span').html();
|
||||
$this.data('originalLabel', labelHTML);
|
||||
}).on('change input', function() {
|
||||
var $this = $(this);
|
||||
var files = $this.prop('files');
|
||||
if (files.length) {
|
||||
$('label[for="' + $(this).attr('id') + '"] span').text(files[0].name);
|
||||
$('label[for="' + $this.attr('id') + '"] span').text(files[0].name);
|
||||
} else {
|
||||
$('label[for="' + $this.attr('id') + '"] span').html($this.data('originalLabel'));
|
||||
}
|
||||
});
|
||||
|
||||
|
2
admin/assets/js/app.min.js
vendored
Normal file → Executable file
2
admin/assets/js/app.min.js
vendored
Normal file → Executable file
File diff suppressed because one or more lines are too long
@ -26,6 +26,14 @@ Formwork.Form = function(form) {
|
||||
});
|
||||
|
||||
function hasChanged() {
|
||||
var $fileInputs = $form.find(':file');
|
||||
if ($fileInputs.length > 0) {
|
||||
for (var i = 0; i < $fileInputs.length; i++) {
|
||||
if ($fileInputs[i].files.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $form.serialize() != $form.data('original-data');
|
||||
}
|
||||
};
|
||||
|
@ -17,10 +17,17 @@ Formwork.Forms = {
|
||||
$target.change();
|
||||
});
|
||||
|
||||
$('input:file').change(function() {
|
||||
var files = $(this).prop('files');
|
||||
$('input:file').each(function() {
|
||||
var $this = $(this);
|
||||
var labelHTML = $('label[for="' + $(this).attr('id') + '"] span').html();
|
||||
$this.data('originalLabel', labelHTML);
|
||||
}).on('change input', function() {
|
||||
var $this = $(this);
|
||||
var files = $this.prop('files');
|
||||
if (files.length) {
|
||||
$('label[for="' + $(this).attr('id') + '"] span').text(files[0].name);
|
||||
$('label[for="' + $this.attr('id') + '"] span').text(files[0].name);
|
||||
} else {
|
||||
$('label[for="' + $this.attr('id') + '"] span').html($this.data('originalLabel'));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user