Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focus lost after update

I have form with two inputs, where one value depends on another. When user change one field I need to recalculate values (this is done in setter methods) and update the form.

This is my example:

<h:form>
<p:inputText id="price1" value="#{bean.price1}"}">
    <p:ajax event="blur" update="@this, price2"/>
</p:inputText>
<p:inputText id="price2" value="#{bean.price2}">
    <p:ajax event="blur" update="@this, price1"/>
</p:inputText>
</h:form>

The problem is that after update focus is lost e.g. if user moves from price1 to price2 using Tab key.

like image 772
karolkpl Avatar asked Sep 29 '26 23:09

karolkpl


1 Answers

You can try this:

<h:form id="fm">
    <script type="text/javascript">
        function test(){
            $(PrimeFaces.escapeClientId('fm:price2')).focus();
        }
    </script>
    <p:inputText id="price1" value="#{bean.price1}" >
        <p:ajax event="blur" oncomplete="test();" update="@this, price2"                listener="#{bean.hand}"/>
    </p:inputText>
    <p:inputText widgetVar="xxx" id="price2" value="#{bean.price2}">
        <p:ajax event="blur" update="@this, price1"/>
    </p:inputText>
</h:form>
like image 175
Rong Nguyen Avatar answered Oct 02 '26 11:10

Rong Nguyen