Skip to content

Commit 3c89f0e

Browse files
committed
add counter.
1 parent 3639cc7 commit 3c89f0e

File tree

1 file changed

+9
-2
lines changed
  • plugins/Sandbox/templates/QrCodeExamples

1 file changed

+9
-2
lines changed

plugins/Sandbox/templates/QrCodeExamples/index.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,21 @@
7272
$field.after($counterDiv);
7373
}
7474

75+
// Function to count Unicode characters properly (UTF-8 safe)
76+
function getUnicodeLength(str) {
77+
// Use the spread operator to split by grapheme clusters
78+
// This handles emojis, combining characters, etc. correctly
79+
return [...str].length;
80+
}
81+
7582
// Bind input event
7683
$field.on('input keyup paste', function() {
77-
var charCount = $(this).val().length;
84+
var charCount = getUnicodeLength($(this).val());
7885
$('#' + counterId).text(charCount);
7986
});
8087

8188
// Initialize counter
82-
$('#' + counterId).text($field.val().length);
89+
$('#' + counterId).text(getUnicodeLength($field.val()));
8390
});
8491
}, 100);
8592
});

0 commit comments

Comments
 (0)