EGL:以编程方式选择dojocurrencytextbox的内容

时间:2017-05-26 08:11:56

标签: dojo egl

更新了新代码。

我已经搜索了这个论坛,但找不到我的问题的解决方案(也许我使用了错误的搜索条件)。 我正在寻找的是一种通过代码(以编程方式)选择DojoCurrencyTextbox内容的方法。 我创建了一个测试程序,当我点击currencytextbox时,内容被选中(通过selectonClick属性)。而且,当我按下一个按钮时,我可以将焦点设置为currencytextbox,但我似乎无法选择内容,对于DOjoTextField它确实有效,但是对于DojoCurrencyTextBox它没有。

我希望有人能告诉我如何使这项功能正常运作。

我使用的测试代码如下:

package dmg.zz_testruben;

// RUI Widget

import com.ibm.egl.rui.widgets.GridLayout;
import com.ibm.egl.rui.widgets.GridLayoutData;
import egl.ui.rui.Event;
import dojo.widgets.DojoButton;
import dojo.widgets.DojoCurrencyTextBox;
import dojo.widgets.DojoTextField;


handler TestSelectCurrencyTextBox type RUIWidget {targetWidget = ui, onConstructionFunction = start}
    ui GridLayout{ columns = 3, rows = 4, cellPadding = 4, children = [txtInput1, btnInput1, btnInput1b, txtInput2, btnInput2, btnInput2b] };

    txtInput1 DojoTextField{layoutData = new GridLayoutData{row=1, column=1}, suppressChangeEvent = true, selectOnClick = true, text = "abc"};
    btnInput1 DojoButton{layoutData = new GridLayoutData{row=1, column=2}, text = "select", onClick ::= btnInput1_onClick};
    btnInput1b DojoButton{layoutData = new GridLayoutData{row=1, column=3}, text = "focus", onClick ::= btnInput1b_onClick};
    txtInput2 DojoCurrencyTextbox{layoutData = new GridLayoutData{row=2, column=1}, suppressChangeEvent = true, selectOnClick = true, text = "1,23"};
    btnInput2 DojoButton{layoutData = new GridLayoutData{row=2, column=2}, text = "select", onClick ::= btnInput2_onClick};
    btnInput2b DojoButton{layoutData = new GridLayoutData{row=2, column=3}, text = "focus", onClick ::= btnInput2b_onClick};

    function start()
    end 



    private function btnInput1_onClick (e Event in)
        txtInput1.children[2].children[1].select();
    end

    private function btnInput2_onClick (e Event in)
        txtInput2.children[2].children[1].select();
    end

    private function btnInput1b_onClick (e Event in)
        txtInput1.focus();
    end

    private function btnInput2b_onClick (e Event in)
        txtInput2.focus();
    end


end

1 个答案:

答案 0 :(得分:0)

在CurrencyTextBox&{39} select上调用focusNode



require([
  "dojo/on",
  "dijit/form/CurrencyTextBox",
  "dojo/domReady!"
], function(on, CurrencyTextBox) { 
  var ctb = new CurrencyTextBox({
    value: "54.12",
    constraints:{fractional:true},
    currency:'USD',
    invalidMessage:'Invalid amount. Cents are required.'
  }).placeAt("result");
  
  ctb.focusNode.select();
});

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dojo/dojo.js"></script>
<div id="result"></div>
&#13;
&#13;
&#13;