1
0
Fork 0
mirror of https://github.com/24eme/signaturepdf synced 2024-06-04 15:02:29 +02:00

Protection du bouton ajouter dans la modal tant qu'il n'y a rien à

ajouter
This commit is contained in:
Vincent LAURENT 2021-10-02 00:48:34 +02:00
parent 0cdba33ee8
commit 5bccb2a5ce
2 changed files with 9 additions and 1 deletions

View file

@ -132,6 +132,8 @@ loadingTask.promise.then(function(pdf) {
maxWidth: 2,
throttle: 0,
onEnd: function() {
document.getElementById('btn_modal_ajouter').setAttribute('disabled', 'disabled');
const file = new File([dataURLtoBlob(signaturePad.toDataURL("image/svg+xml"))], "draw.svg", {
type: 'image/svg+xml'
});
@ -143,6 +145,7 @@ loadingTask.promise.then(function(pdf) {
var svgImage = "data:image/svg+xml;base64,"+btoa(trimSvgWhitespace(this.responseText));
document.getElementById('img-upload').src = svgImage;
document.getElementById('img-upload').classList.remove("d-none");
document.getElementById('btn_modal_ajouter').removeAttribute('disabled');
document.getElementById('btn_modal_ajouter').focus();
};
xhr.send( data );
@ -162,6 +165,7 @@ loadingTask.promise.then(function(pdf) {
document.getElementById('modalAddSvg').addEventListener('hidden.bs.modal', function (event) {
signaturePad.clear();
document.getElementById('btn_modal_ajouter').setAttribute('disabled', 'disabled');
document.getElementById('input-text-signature').value = null;
document.getElementById('input-image-upload').value = null;
document.getElementById('img-upload').src = null;
@ -170,12 +174,15 @@ loadingTask.promise.then(function(pdf) {
})
document.getElementById('input-text-signature').addEventListener('keypress', function(event) {
document.getElementById('btn_modal_ajouter').removeAttribute('disabled');
if(event.key == 'Enter') {
document.getElementById('btn_modal_ajouter').removeAttribute('disabled');
document.getElementById('btn_modal_ajouter').click()
}
})
document.getElementById('input-image-upload').addEventListener('change', function(event) {
document.getElementById('btn_modal_ajouter').setAttribute('disabled', 'disabled');
var data = new FormData();
data.append('file', document.getElementById('input-image-upload').files[0]);
@ -186,6 +193,7 @@ loadingTask.promise.then(function(pdf) {
var svgImage = "data:image/svg+xml;base64,"+btoa(trimSvgWhitespace(this.responseText));
document.getElementById('img-upload').src = svgImage;
document.getElementById('img-upload').classList.remove("d-none");
document.getElementById('btn_modal_ajouter').removeAttribute('disabled');
document.getElementById('btn_modal_ajouter').focus();
};
xhr.send( data );

View file

@ -74,7 +74,7 @@
</div>
<div class="modal-footer">
<button tabindex="-1" type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
<button id="btn_modal_ajouter" type="button" class="btn btn-primary" data-bs-dismiss="modal">Ajouter</button>
<button id="btn_modal_ajouter" type="button" disabled="disabled" class="btn btn-primary" data-bs-dismiss="modal">Ajouter</button>
</div>
</div>
</div>