I have a <p:editor />
with attribute maxlength but the user can paste text bigger than maxlength.
Here all what I tried to check if what is paste is longer than max lenght and if its true I want to cut substring (0,max) the pasted text.
document.getElementById("editor").onpaste = function(e){
var max = document.getElementById("editor").getAttribute("maxlength");
e.clipboardData.getData('text/plain').slice(0, max);
};
$('.editor').live('paste', function(){
console.log('function');
if ($('.editor').val().length > 140) {
console.log('errrrrrrrrrrrorrrrrrrrrrrrrrrrr');
$('.editor').val($('#editor').val().substr(0,10));
}
});
var max = 140;
$('#shopCustomizationForm\\:rongnk').find('iframe').contents().find("body").on('keyup', function(e) {
ilength = $('#shopCustomizationForm\\:rongnk').find('iframe').contents().find("body").text().length;
$('#shopCustomizationForm\\:txt').html('Remain:' + (max - ilength));
});
XHTML:
<p:editor widgetVar="CEMessage_Widget"
id="editor"
value="#{dcShopCustomizationManagedBean.customBean.customText}"
controls="bold italic underline strikethrough color size alignleft center alignright justify bullets numbering"
maxlength="140" />