From f1215cf41119c8babdce6e9723bbe116c0bf1855 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 25 Mar 2021 19:25:30 +0100 Subject: [PATCH] Aggiunta informazione dei caratteri digitati per le textarea --- assets/src/js/functions/input.js | 10 ++++++++-- assets/src/js/functions/textarea.js | 18 ++++++++++++++++++ gulpfile.js | 1 + modules/anagrafiche/edit.php | 2 +- package.json | 1 + 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/assets/src/js/functions/input.js b/assets/src/js/functions/input.js index 9c5377d9e..081c30e8c 100644 --- a/assets/src/js/functions/input.js +++ b/assets/src/js/functions/input.js @@ -103,8 +103,14 @@ Input.prototype.init = function () { } // Inizializzazione per textarea - else if (this.element.hasClass('autosize')) { - initCompleted = initTextareaInput(htmlElement); + else if (this.element.hasClass('autosize') || htmlElement.hasAttribute('maxlength')) { + + if (this.element.hasClass('autosize')) + initCompleted = initTextareaInput(htmlElement); + + if (htmlElement.hasAttribute('maxlength')) + initCompleted = initCharsCounter(htmlElement); + } // Inizializzazione per select diff --git a/assets/src/js/functions/textarea.js b/assets/src/js/functions/textarea.js index 0f18d5428..bba5c5438 100644 --- a/assets/src/js/functions/textarea.js +++ b/assets/src/js/functions/textarea.js @@ -26,6 +26,24 @@ function initTextareaInput(input) { return true; } +function initCharsCounter(input) { + let $input = $(input); + + $input.maxlength({ + warningClass: "label label-info", + limitReachedClass: "label label-warning", + preText: 'usati ', + separator: ' di ', + postText: ' caratteri.', + showMaxLength: false, + placement: 'bottom-right-inside', + utf8: true, + appendToParent: true + }); + + return true; +} + function waitCKEditor(input) { setTimeout(function () { initEditorInput(input); diff --git a/gulpfile.js b/gulpfile.js index 00d2977a0..9d4780587 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -115,6 +115,7 @@ const JS = gulp.parallel(() => { 'datatables.net-bs/js/dataTables.bootstrap.js', 'datatables.net-buttons-bs/js/buttons.bootstrap.js', 'smartwizard/dist/js/jquery.smartWizard.min.js', + 'bootstrap-maxlength/dist/bootstrap-maxlength.js', ]; for (const i in vendor) { diff --git a/modules/anagrafiche/edit.php b/modules/anagrafiche/edit.php index f9428d13a..b47a87fb5 100755 --- a/modules/anagrafiche/edit.php +++ b/modules/anagrafiche/edit.php @@ -672,7 +672,7 @@ if ($is_cliente or $is_fornitore or $is_tecnico) {
- {[ "type": "textarea", "label": "", "name": "note", "value": "$note$" ]} + {[ "type": "textarea", "label": "", "name": "note", "value": "$note$", "maxlength": 255 ]}
diff --git a/package.json b/package.json index 792f3300a..a7a5d090d 100755 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "bootstrap": "^3.3.7", "bootstrap-colorpicker": "2.5.1", "bootstrap-daterangepicker": "^2.1.25", + "bootstrap-maxlength": "1.10.0", "chart.js": "^2.7.0", "ckeditor4-dev": "^4.14.1", "components-jqueryui": "^1.12.1",