Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically set focus on p:editor on page load

How do I automatically set the focus on <p:editor> on page load?

After page is loaded I would like to be able to write in the editor without an additional click on the editor panel.

like image 682
leostiw Avatar asked Dec 07 '25 00:12

leostiw


1 Answers

Primefaces provide attribute 'widgetVar', so you can get element from client and focus it:

<h:head>
        <script type="text/javascript">
            function test() {
                xxx.focus();
            }
        </script>
    </h:head>
    <h:body onload="test()">        
        <h:form id="form">  
            <p:inputText id="rongnk" value="test"/>
            <p:editor widgetVar="xxx" id="nkrong" value="123" width="600"/>  
        </h:form>  
    </h:body>
like image 111
Rong Nguyen Avatar answered Dec 09 '25 04:12

Rong Nguyen