سؤال

My goal is to set the focus to a specific inputText.

As there seems to be no way to do this automatically with an tr:inputText property, I try to use Javascript.

For document.getElementById I need the id of the rendered html <input>. I try to set this id to the correct index. However, it is rendered with the id varFieldIterator:0:varField where the number 0 comes from the iterator and is different depending on my start value selectionStart. If I start with selectionStart = 10, the 1st index for the textbox 10 is 0. If I start with 15 and then have a PPR to show the first 15 textboxes, they get the id starting with 16.

I think the code will make clear what I try to achieve:

<tr:iterator
    id="varFieldIterator"
    value="#{myController.form.model.fieldList}"
    var="field"
    rows="15"
    first="#{{myController.form.model.selectionStart}"
    varStatus="status">
  <tr:inputText
      id="varField#{status.index}"
      value="#{field.value}"
      label="Text #{status.index +1}">
</tr:iterator>

<tr:inputHidden
    id="FOCUS_TEXT"
    value="#{myController.form.model.endFocus}"></tr:inputHidden>
<trh:script>
window.onload = function() { document.getElementById('varField' + document.getElementById('FOCUS_TEXT').value).focus(); } 
</trh:script>

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top