Characters left for p: editor

I know that Primefaces provides functionality for the character left for p: inputTextarea, as shown in the code below

<p:inputTextarea rows="1" cols="85" counter="counter" maxlength="100" counterTemplate="{0} characters remaining" value="#{managedBean.inputvalue}" ></p:inputTextarea> <h:outputText /> <h:outputText id="counter" /> 

But I want to do the same in p: editor. How to do it? Is primacy such functionality or should I achieve it in other ways (for example, coding this functionality).

TIA

+4
source share
2 answers

<p:editor does not have an option for this, you can use jquery to solve it. My solution is the event of binding binding to your editor. I just tested, my example has one form (id: fm), one editor (id: rongnk), one output text (id: txt):

 <h:body onload="bindiframe()"> <h:form id="fm"> <p:editor id="rongnk" value="xxx"> </p:editor> <h:outputText id="txt"/> <script type="text/javascript"> var imax = 50; function bindiframe(){ $('#fm\\:rongnk').find('iframe').contents().find("body").on('keyup', function(e) { ilength = $('#fm\\:rongnk').find('iframe').contents().find("body").text().length; $('#fm\\:txt').html('Remain:' + (imax - ilength)); }); } </script> </h:form> </h:body> 
+7
source

As far as I can tell from the documentation <p:editor> tag , there is no attribute with the counter function. However, there is a maxlength attribute.

So, it’s best to attach a JavaScript function to handle the change event by specifying onchange="checkTextLength(this)" . To write this function, you need to calculate the difference between the maximum text length and the current text length using the PrimeFaces client APIs and based on updating the placeholder result.

+3
source

Source: https://habr.com/ru/post/1479886/


All Articles