如何将焦点设置为重复控件内的编辑框? [英] How can I set focus to Edit Box inside repeat control?

查看:31
本文介绍了如何将焦点设置为重复控件内的编辑框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将焦点 + 放置光标设置到 repreat 控件中的编辑框(最后一个).重复位于面板 (panelRep) 内.然后我在面板外有一个按钮.

I would like to set focus + place cursor to an Edit Box (the last one) within a repreat control. The repeat is inside a panel (panelRep). I then have a button outside the panel.

这是几乎可以工作的按钮的客户端代码.设置了焦点(字段周围的蓝色边框),但光标未放置在字段中.用户仍必须单击该字段才能写入输入内容.

This is the client side code for the button which almost works.. Focus is set (blue border around field), but cursor is not placed in field. User must still click the field to be able to write input.

没有焦点的例子:

Example without focus:

焦点示例:

按钮的客户端代码,它将焦点设置到最后一个编辑框,其中 id 包含字符串 inputKode:

Client side code for button which sets focus to last Edit Box in which id contains the string inputKode:

try {
var el = dojo.query('div[id*="inputKode"]');
var node = el[el.length-1];
setTimeout(function() { node.focus(); }, 500);
//node.focus();
} catch (e) { } 

panelRep 的代码:

Code for panelRep:

<xp:panel id="panelRep">
            <xp:repeat id="repeat1" rows="12" var="row" indexVar="idx"
                value="#{view1}" repeatControls="false">
                <xp:panel id="panelLinje">
                    <xp:this.data>
                        <xp:dominoDocument formName="frmPBudKodeVerdi"
                            var="dsdoc" action="editDocument" computeWithForm="both"
                            documentId="#{javascript:row.getUniversalID();}">                           
                        </xp:dominoDocument>
                    </xp:this.data>
                    <xp:table style="width:800.0px">
                        <xp:tr>
                            <xp:td style="width:100px">
                                <xp:inputText id="inputKode"
                                    value="#{dsdoc.KodeNr}" style="width:62px">
                                    <xp:this.attrs>
                                        <xp:attr name="tabindex"
                                            value="#{javascript:return idx + '1';}">
                                        </xp:attr>
                                    </xp:this.attrs>
                                    <xp:typeAhead mode="partial"
                                        minChars="1" var="lukey" valueMarkup="true" id="typeAhead1">
                                        <xp:this.valueList><![CDATA[#{javascript://var type = compositeData.type;
                                        return TypeAheadKode2(sessionScope.type,lukey);
                                        }]]></xp:this.valueList>    
                                    </xp:typeAhead>
                                    <xp:eventHandler event="onchange"
                                        submit="true" refreshMode="partial" refreshId="panelLinje">
                                        <xp:this.action><![CDATA[#{javascript:onChangeKode();}]]></xp:this.action>
                                    </xp:eventHandler>
                                </xp:inputText>                             
                            </xp:td>
                            <xp:td style="width:450px">
                                <xp:inputText id="inputNavn"
                                    value="#{dsdoc.KodeNavn}" style="width:440px"
                                    readonly="true">
                                </xp:inputText>
                            </xp:td>
                            <xp:td style="width:60px">
                                <xp:inputText id="inputNorm"
                                    style="width:45px" value="#{dsdoc.NormPrProd}"
                                    rendered="#{javascript:viewScope.visNorm}" readonly="true">
                                    <xp:this.attrs>
                                        <xp:attr name="tabindex"
                                            value="#{javascript:return idx + '2';}">
                                        </xp:attr>
                                    </xp:this.attrs>
                                    <xp:this.converter>
                                        <xp:convertNumber
                                            type="number">
                                        </xp:convertNumber>
                                    </xp:this.converter>
                                </xp:inputText>
                            </xp:td>
                            <xp:td style="width:50px">
                                <xp:inputText id="inputAntall"
                                    style="width:45px" value="#{dsdoc.NormAntall}"
                                    rendered="#{javascript:viewScope.visNorm}">
                                    <xp:this.converter>
                                        <xp:convertNumber
                                            type="number">
                                        </xp:convertNumber>
                                    </xp:this.converter>
                                    <xp:eventHandler
                                        event="onchange"
                                        submit="true"
                                        refreshMode="partial"
                                        refreshId="inputTimer">
                                        <xp:this.action><![CDATA[#{javascript:onChangeAntall()}]]></xp:this.action>
                                    </xp:eventHandler>
                                    <xp:this.attrs>
                                        <xp:attr name="tabindex"
                                            value="#{javascript:return idx + '3';}">
                                        </xp:attr>
                                    </xp:this.attrs>
                                </xp:inputText>
                            </xp:td>
                            <xp:td
                                style="width:50px;text-align:right">
                                <xp:inputText id="inputTimer"
                                    value="#{dsdoc.Timer}" style="width:45px;text-align:right">
                                    <xp:this.converter>
                                        <xp:convertNumber
                                            type="number">
                                        </xp:convertNumber>
                                    </xp:this.converter>
                                    <xp:this.attrs>
                                        <xp:attr name="tabindex"
                                            value="#{javascript:return idx + '4';}">
                                        </xp:attr>
                                    </xp:this.attrs>
                                </xp:inputText>
                            </xp:td>
                            <xp:td>                             
                            </xp:td>
                        </xp:tr>
                    </xp:table>
                    <xp:eventHandler event="onClientLoad" submit="true"
                        refreshMode="norefresh">
                    </xp:eventHandler>
                </xp:panel>
            </xp:repeat>
</xp:panel>

推荐答案

22.09.2012 更新:

Update 22.09.2012:

@MarkyRoden - 感谢您为我指明正确的方向.

@MarkyRoden - Thanks for pointing me in the right direction.

在优化 dojo.query 选择器后,我得到了 1 行代码.

After refining the dojo.query selector, I ended up with 1 line of code.

var el = dojo.query('div[id*="inputKode"] .dijitInputField > input').at(-1)[0].focus(); 



原帖:



Original post:

我发现设置焦点的元素不是 INPUT 元素.元素 ID 以 widget_

I found out that the element being set focus on was not an INPUT element. Element id started with widget_

例如 widget_view:_id1:_id2:_id3:repeat1:8:inputKode 如果重复中有 8 行

E.g widget_view:_id1:_id2:_id3:repeat1:8:inputKode if there are 8 rows in the repeat

然后我发现元素的nodeType是DIV通过查看 element.innerHTML,我发现它有多个子元素.

I then discovered that the nodeType of the element was DIV By viewing the element.innerHTML, I discovered that it had multiple children.

我尝试使用 element.querySelector 或 element.querySelectorAll,但我无法让它们为元素工作,所以我最终通过 element.childNodes 循环.不是很漂亮,但它现在可以工作..

I tried to use element.querySelector or element.querySelectorAll, but I couldn't get them to work for the element, so I ended up looping through element.childNodes. Not very pretty, but it does the work for now..

我确信通过向 dojo.query 选择器添加元素或使用 jquery 可以做得更好.以后得研究一下..

I'm sure it can be done much nicer by adding elements to the dojo.query selector, or by using jquery. Have to look into that later..

好吧,这是我为 CC 放入 onClientLoad 事件的代码:

Well, here's the code I put in the onClientLoad event for my CC:

var el = dojo.query('div[id*="inputKode"]');
var node = el[el.length-1];
node.focus();

var activeElementId = document.activeElement.id;
var activeElement = dojo.byId( activeElementId );
var kids = activeElement.childNodes;

for(var i=0; i < kids.length; i++)
{
    if(kids[i].className == 'dijitReset dijitInputField dijitInputContainer')
    {
    var elementDiv = kids[i];
    var elementDivKids = elementDiv.childNodes;

    for(var j=0; j < elementDivKids.length; j++)
    {
        var elementInput = elementDivKids[j];
        elementInput.focus();
    }
    } 
}

问候,彼得

这篇关于如何将焦点设置为重复控件内的编辑框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆