File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
plugins/Sandbox/templates/QrCodeExamples Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 72
72
$field.after($counterDiv);
73
73
}
74
74
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
+
75
82
// Bind input event
76
83
$field.on('input keyup paste', function() {
77
- var charCount = $(this).val().length ;
84
+ var charCount = getUnicodeLength( $(this).val()) ;
78
85
$('#' + counterId).text(charCount);
79
86
});
80
87
81
88
// Initialize counter
82
- $('#' + counterId).text($field.val().length );
89
+ $('#' + counterId).text(getUnicodeLength( $field.val()) );
83
90
});
84
91
}, 100);
85
92
});
You can’t perform that action at this time.
0 commit comments