0

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" />
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • And the actual coding problem is? (the line where an error occurs or something that you think is/should be happening is not) – Kukeltje Oct 16 '18 at 15:50
  • the actual problem is that i can paste all i want nothing it happening it is not enter in my function but i don't know why? – Atif Souidi Oct 16 '18 at 16:02
  • So the actual coding problem is that the `$('.editor').live('paste', function(){ console.log('function');`.... });` is not being called? So either the `paste` event is not fired (where did you read it should) or the `live(....)` is not working or your selector is not right, or one of the similar issues with the other functions. Can't you narrow that down? – Kukeltje Oct 16 '18 at 16:15
  • I'm 100% sure your selectors are wrong... https://stackoverflow.com/questions/6045307/how-can-i-know-the-id-of-a-jsf-component-so-i-can-use-in-javascript – Kukeltje Oct 16 '18 at 16:28

0 Answers0