Question

I am trying get currently focused component id. For this I used following jQuery:

<script>
    $(document).ready(function(){
        $("*").focus(function(){
            $('#hiddenInput').val($(this).attr('name'));
        });
    });
</script>

I have a tabview with 2 tabs, and tabview dynamic attribute is set to true. jQuery is not getting fired for components of tab2 when I switch to tab2. I have noticed that HTML source is not getting generated for components of tab2. How do I resolve the issue ?

Generated Markup given below :

<div class="ui-tabs-panels">
    <div id="j_idt76:j_idt77" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-hidden="false">
        <table cellpadding="5" cellspacing="5">
            <tbody>
                <tr>
                    <td><label> Customer ID</label></td>
                    <td>
                        <input id="j_idt76:j_idt82" name="j_idt76:j_idt82" type="text" value="0893000453 " size="45" readonly="readonly" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" />
                        <script id="j_idt76:j_idt82_s" type="text/javascript">PrimeFaces.cw('InputText','widget_j_idt76_j_idt82', id:'j_idt76:j_idt82'});</script>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="j_idt76:j_idt147" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-helper-hidden" role="tabpanel" aria-hidden="true"></div>
</div>
Was it helpful?

Solution

<script>
        $(document).ready(function(){
             $("body").delegate(":input", "focus", function(){
                 $('#hiddenInput').val($(this).attr('name'));
              });
        });
</script>


We can achieve this using delegate function.

OTHER TIPS

markup of tabview given below...

I have noticed couple of thing's,

1.Even I click tab2, markup for components in tab2 are not generated, so unable to access the component.

2.When I updated my form using Ajax, I am unable to access the components, which was accessable before ajax call.

    <div class="ui-tabs-panels">
             <div id="j_idt76:j_idt77" role="tabpanel" aria-hidden="false">
                                    <table>
                                        <tbody>
                                            <tr>
                                                <td><input id="j_idt76:j_idt82" name="j_idt76:j_idt82" type="text" /></td>
                                                Other components....
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
              <div id="j_idt76:j_idt147" role="tabpanel" aria-hidden="true"></div>
        </div>

In the above code, markup for components in Tab1(j_idt76:j_idt77) are generated, but not for Tab2(j_idt76:j_idt147).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top