Inputtext edit in Tree - loosing focus!

UI Components for JSF
Post Reply
red_beard
Posts: 4
Joined: 22 Jul 2016, 06:36

21 Aug 2016, 06:25

Hello
I faced the following issue:
i have tree and inputText in it. When selecting the text in input window the focus moves out of the input window, thus preventing edit.
It could be moved back using TAB key.
I found number of similar questions with no answer for workaround or solution.
http://stackoverflow.com/questions/2183 ... -inputtext
http://forum.primefaces.org/viewtopic.php?f=3&t=36443


I am using primefaces 5.
How to resolve this issue?
Thank you for help in advance

red_beard
Posts: 4
Joined: 22 Jul 2016, 06:36

23 Aug 2016, 04:43

I resolved by myself but i am not sure about possible side effects.
I see one of them as NOT selecting the tree node where input is located, i.e. by default focus first comes to input control then it goes to the parent object that contains it, i.e. treeNode. Tree node color does not change (as it is "not selected"). Probably it could be fixed by sending event to the parent before stopping focus propagation. Not sure though.

BTW, same issue experienced with textarea in tree:
so my input node is as follows:

Code: Select all

<p:tree  id="TreeId" value="..." var="node" > 
....
<p:treeNode type=".... >
    <h:inputTextarea value="#{node.value}" styleClass="..." onclick="stopProp(event);" 	style="... " 	autoResize="false" rows="5">
    <p:ajax />
</h:inputTextarea>
</p:treeNode>

<h:inputText value="#{node.value}"  styleClass="..." onclick="stopProp(event);"  style="..."  > 
 	<p:ajax /> 
 </h:inputText>
</p:treeNode>
</p:tree>


<script type="text/javascript">
function stopProp ( event ) {
				 event.currentTarget.focus();
				 event.currentTarget.select();
				 event.stopPropagation();
				}
</script>

red_beard
Posts: 4
Joined: 22 Jul 2016, 06:36

25 Aug 2016, 05:16

even better: now the node is selected and focus is set to inputtext

Code: Select all

function stopProp ( event ) {
				  var target = event.currentTarget;
				   setTimeout(
						   function(){
							   target.focus();
							   target.select(); }, 
							   100);
				}

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests