-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I need to implement a "remember last typed value" functionality to be triggered by pressing F2; something like this:
<textbox ctrlKeys="#f2" onCtrlKey='self.setValue( "jauja" );' constraint="no empty"/>
The problem with this approach lies on the error message box appearing and disappearing as a result of the specified constraint (which, alas, I cannot do without) being violated for a brief moment.
I've tried to overwrite some widget methods, with no satisfactory result:
<window xmlns:w="client">
<textbox ctrlKeys="#f2" onCtrlKey='self.setValue( "jauja" );' constraint="no empty">
<attribute w:name="doKeyDown_">
function( event ) {
if( event.keyCode == 113 ) {
this.__ignore = true;
}
this.$doKeyDown_( event );
}
</attribute>
<attribute w:name="validate_">
function( value ) {
if( this.__ignore ) {
this.__ignore = false;
return false;
} else {
this.$validate_( value );
}
}
</attribute>
</textbox>
</window>
(The error message does not popup, but no validation seems to be carried out whatsoever).
Any advice as to how to implement this would be much appreciated
César Varona
you can override the beforeCtrlKeys_() method and disable/reenable the constraints around the default behaviour of the widget only for the short moment where it is not required.
<script>
zk.afterLoad("zul.inp", function () {
zk.$package("zul.inp").TextboxNoErrorOnCtrlKey = zk.$extends(zul.inp.Textbox, {
beforeCtrlKeys_: function (event) {
//maybe check for event.keyCode==113 here if you need other ctrlKeys
this.getConstraint().getFlags().NO_EMPTY=false;
this.$supers("beforeCtrlKeys_", event);
this.getConstraint().getFlags().NO_EMPTY=true;
}
});
});
</script>
now you can use the class on several textboxes on the same page
<textbox w:use="zul.inp.TextboxNoErrorOnCtrlKey" id="withCtrlKey" onCtrlKey='self.setValue( "jauja" );' ctrlKeys="#f2" constraint="no empty" />
Thanks a lot cor3000 for your tips and example, which I've modified like this in order to make it valid for any constraint:
<window xmlns:w="client">
<textbox ctrlKeys="#f2" onCtrlKey='self.setValue( "jauja" );' constraint="no empty">
<attribute w:name="beforeCtrlKeys_">
function (event) {
if( this._cst ) {
this.__aux = this._cst;
this._cst = null;
}
this.$supers("beforeCtrlKeys_", event);
if( this.__aux ) {
this._cst = this.__aux;
}
}
</attribute>
</textbox>
</window>
It works nicely.
With kind regards
César Varona
Asked: 2013-05-23 15:41:22 +0800
Seen: 42 times
Last updated: May 24 '13
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status