1

Some way to skip client validation for certain input values [closed]

asked 2013-05-23 15:41:22 +0800

cvarona gravatar image cvarona
554 1 6

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

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cvarona
close date 2013-05-24 08:21:36

2 Answers

Sort by » oldest newest most voted
1

answered 2013-05-24 07:26:44 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2013-05-24 07:33:20 +0800

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" />
link publish delete flag offensive edit
0

answered 2013-05-24 08:20:45 +0800

cvarona gravatar image cvarona
554 1 6

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

link publish delete flag offensive edit

Question tools

Follow
3 followers

RSS

Stats

Asked: 2013-05-23 15:41:22 +0800

Seen: 42 times

Last updated: May 24 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More