<script>
$(document).ready(function(){
$("body").delegate(":input", "focus", function(){
$('#hiddenInput').val($(this).attr('name'));
});
});
</script>
We can achieve this using delegate function.
Accessing Tab2 components from jQuery
-
27-11-2021 - |
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>
Solution
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).