Events in Safari
Hi Dani,
That is because safari not trigger the onfocus when click on checkbox,
you can try the html fragment below
<html>
<head>
<script type="text/javascript">
var s = "result: "
function doClick () {
s += '\nonclick';
document.getElementById('ta').value = s;
}
function doFocus () {
s += '\nonfocus';
document.getElementById('ta').value = s;
}
</script>
</head>
<body>
<input type="checkbox" value="test checkbox" onclick="doClick();" onfocus="doFocus();">test checkbox</input>
<textarea id="ta" style="width: 200px; height: 300px">result: </textarea>
</body>
</html>
so ZK trigger it manually and the timeing may not meet your need,
you can try override javascript on your zul page or the device config in zk.xml as below:
<script type="text/javascript">
zk.afterLoad("zul.wgt", function () {
if (zk.safari) {
var oldFOC = zul.wgt.Checkbox.prototype.fireOnCheck_,
oldFocus = zul.wgt.Checkbox.prototype.doFocus_,
oldBlur = zul.wgt.Checkbox.prototype.doBlur_;
// this is the main part,
// override this fragment will let onCheck event triggered later.
zul.wgt.Checkbox.prototype.fireOnCheck_ = function (checked) {
var wgt = this;
setTimeout(function () {
oldFOC.apply(wgt, arguments);
}, 0);
};
// below may not required,
// the onCheck will still triggered after onFocus if
// remove the two fragment below
// but the onFocus will triggered every time
// (it only triggered once before you click else where on other browser)
zul.wgt.Checkbox.prototype.doFocus_ = function (evt) {
if (this.clearRealFocus) {
clearTimeout(this.clearRealFocus);
this.clearRealFocus = null;
}
if (!this.realFocus) {
oldFocus.apply(this, arguments);
this.realFocus = true;
}
};
zul.wgt.Checkbox.prototype.doBlur_ = function (evt) {
oldBlur.apply(this, arguments);
var wgt = this;
this.clearRealFocus = setTimeout(function () {
wgt.realFocus = null;
wgt.clearRealFocus = null;
}, 200);
};
}
});
</script>
for the device config in zk.xml, please refer to zk.xml/The device-config Element/The embed Element
Regards,
ben
Hi Ben...
Thanks a lot. Still I have to study this code but... it is very instructive. I added that code to my zk.xml (just first part because I think I don´t need the focus and blur functions). With trace I know it is working. Now I have a new problem (still with Safari).
In my onCheck event I look for state of the component with:
myCheck.addEventListener(Events.ON_CHECK, new SerializableEventListener() {
@Override
public void onEvent(Event event) throws Exception {
System.out.println("ON_CHECK");
if(myCheck.isChecked())
method2();
}
});
and it fires the event but... it ALWAYS returns false ???? so never calls method2( ). Can you tell me why?
Regards
Hi,
My fault, please modify the first part as below:
<script type="text/javascript">
zk.afterLoad("zul.wgt", function () {
if (zk.safari) {
var oldFOC = zul.wgt.Checkbox.prototype.fireOnCheck_,
oldFocus = zul.wgt.Checkbox.prototype.doFocus_,
oldBlur = zul.wgt.Checkbox.prototype.doBlur_;
// this is the main part,
// override this fragment will let onCheck event triggered later.
zul.wgt.Checkbox.prototype.fireOnCheck_ = function (checked) {
zk.log(checked);
var wgt = this,
args = arguments; // keep the arguments
setTimeout(function () {
oldFOC.apply(wgt, args);
}, 0);
};
}
});
</script>
Regards,
ben
Hi Ben...
Thank you very much!!, it fixed the problem. I tryed and now it seems to work fine.
Regards
ZK - Open Source Ajax Java Framework
Hi...
I am using ZK 5.0.9
I have problems with events in a Checkbox. My code is a little more complex, but suming up is more or less like:
.... myCheck = (Checkbox)ventana.getFellow("DECL_COMPLEMENTARIA"); myCheck.addEventListener(Events.ON_FOCUS, new SerializableEventListener() { @Override public void onEvent(Event event) throws Exception { System.out.println("ON_FOCUS"); method1(); } }); myCheck.addEventListener(Events.ON_CHECK, new SerializableEventListener() { @Override public void onEvent(Event event) throws Exception { System.out.println("ON_CHECK"); method2(); } }); ....So... when I came from another component I need to fire the method1() (with ON_FOCUS event), and the method2() (with ON_CHECK event), and of course with that order. It works fine with IE(7.0.6) and Mozilla(3.6.10)... but with Safari (5.0.3) I see it fires first the ON_CHECK event and then the ON_FOCUS... ?????
Is that a bug?, am I doing something wrong?
Regards,
Dani