所以我想在点击后根据复选框的值启用或禁用日期框。我可以在服务器端执行此操作,如下所示,但似乎无法弄清楚如何在客户端进行此操作。我的问题是,如果没有调用服务器,我似乎无法访问复选框的值。有任何想法吗?
var chkPaid = app.createCheckBox("Paid in Full").setName("paidInFull").setId("paidInFull");
var dateBox2 = app.createDateBox().setName("paidThrough").setFormat(UiApp.DateTimeFormat.DATE_MEDIUM).setEnabled(false).setId("paidThru");
var paidThruDisable = app.createServerHandler("disableHandler");
paidThruDisable.addCallbackElement(chkPaid);
chkPaid.addValueChangeHandler(paidThruDisable);
function disableHandler(e){
var app = UiApp.getActiveApplication();
var widget = app.getElementById("paidThru");
if(e.parameter.paidInFull !== "true"){
widget.setEnabled(false);
}else{
widget.setEnabled(true);
};
return app;
}
答案 0 :(得分:1)
这是我编写的一段代码,可以解决问题; - )
您可以在线测试here
function doGet() {
var app = UiApp.createApplication()
var chkPaida = app.createCheckBox("Paid in Full").setValue(true);
var chkPaidb = app.createCheckBox("Paid in Full").setVisible(false);
var checkpanel = app.createHorizontalPanel().add(chkPaida).add(chkPaidb)
var dateBox2 = app.createDateBox().setName("paidThrough").setFormat(UiApp.DateTimeFormat.DATE_MEDIUM).setId("paidThru").setName("paidThru");
var Chandlera = app.createClientHandler().forTargets(dateBox2).setEnabled(false).forTargets(chkPaidb).setVisible(true).setValue(false)
.forEventSource().setVisible(false)
chkPaida.addClickHandler(Chandlera)
var Chandlerb = app.createClientHandler().forTargets(dateBox2).setEnabled(true).forTargets(chkPaida).setVisible(true).setValue(true)
.forEventSource().setVisible(false)
chkPaidb.addClickHandler(Chandlerb)
app.add(checkpanel).add(dateBox2)
return app
}