passing context to form validation callbacks

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

passing context to form validation callbacks

Burak Arslan-2
hi,

in e.g. http://demo.qooxdoo.org/1.1.x/demobrowser/#ui~FormValidator.html
there's multiple calls like this:

 manager.add(username, userNameValidator);

it'd be nice to be able to pass context information to those functions, like this:

 manager.add(username, userNameValidator, this);

api says I can't. any reason why not? is there a way to do this, or should i file an enhancement bug?

thanks,
burak


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Daniel Wagner
Administrator
Hi Burak,

Martin agrees it shouldn't be a big deal to add a context parameter, so
feel free to open a bug report.

In the mean time, you can use qx.lang.Function.bind to set the context
of your validator function.


Regards,
Daniel

Burak Arslan schrieb:

> hi,
>
> in e.g. http://demo.qooxdoo.org/1.1.x/demobrowser/#ui~FormValidator.html
> there's multiple calls like this:
>
>  manager.add(username, userNameValidator);
>
> it'd be nice to be able to pass context information to those functions, like this:
>
>  manager.add(username, userNameValidator, this);
>
> api says I can't. any reason why not? is there a way to do this, or should i file an enhancement bug?
>
> thanks,
> burak
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Derrell Lipman
On Mon, May 3, 2010 at 10:24, Daniel Wagner <[hidden email]> wrote:
Hi Burak,

Martin agrees it shouldn't be a big deal to add a context parameter, so
feel free to open a bug report.

In the mean time, you can use qx.lang.Function.bind to set the context
of your validator function.

And if you find yourself using the static method qx.lang.Function.bind(...) a lot and would prefer to be able to just say this.bind(...) you use this code in your applicaiton:

      // Add a bindTo() method to qx.core.Object as a shortcut to constantly
      // having to use qx.lang.Function.bind()
      qx.Class.include(qx.core.Object, custom.MObject);

Here's the actual mixin to add to your project:

/* ************************************************************************

   Copyright:
     2009 Derrell Lipman

   License:
     LGPL: http://www.gnu.org/licenses/lgpl.html
     EPL: http://www.eclipse.org/org/documents/epl-v10.php
     See the LICENSE file in the project's top-level directory for details.

   Authors:
     * Derrell Lipman (derrell)

************************************************************************ */

/**
 * Mixin to add a bindTo method to qx.core.Object
 */
qx.Mixin.define("custom.MObject",
{
  members :
  {
    /**
     * Bind a function to this object
     *
     * @param func {Function}
     *   The function to be bound
     *
     * @param varargs {Any?}
     *   Optional arguments to be passed to the function.
     *
     * @return {Function}
     *   A wrapped version of the function that binds 'this' to the
     *   user-provided function.
     */
    bindTo : function(func, varargs)
    {
      return qx.lang.Function.create(
        func,
        {
          self  : this,
          args  : (arguments.length > 1
                   ? qx.lang.Array.fromArguments(arguments, 1) :
                   null)
        });
    }
  }
});


------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Burak Arslan-2
In reply to this post by Daniel Wagner
On 05/03/10 17:24, Daniel Wagner wrote:
> Hi Burak,
>
> Martin agrees it shouldn't be a big deal to add a context parameter, so
> feel free to open a bug report.
>
>  

http://bugzilla.qooxdoo.org/show_bug.cgi?id=3672

> In the mean time, you can use qx.lang.Function.bind to set the context
> of your validator function.
>  

this is very useful to know, thanks a lot

best,
burak



------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

rsantiagopaz
In reply to this post by Daniel Wagner
"In the mean time, you can use qx.lang.Function.bind to set the context
of your validator function."


very good.
With this problem I use this rustic solution for example:

var context = this;
var userNameValidator = function() {
    context.debug("demo");
    return true;
}
manager.add(username, userNameValidator);
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
In reply to this post by Derrell Lipman
Hi Derrell,

wouldn't it make sense to ask for addition of this directly to the
qx.core.Object? Or to at least add your mixin to the standard distribution?

Cheers,
Fritz

On Mon, 3 May 2010, Derrell Lipman wrote:

> On Mon, May 3, 2010 at 10:24, Daniel Wagner <[hidden email]> wrote:
>
>> Hi Burak,
>>
>> Martin agrees it shouldn't be a big deal to add a context parameter, so
>> feel free to open a bug report.
>>
>> In the mean time, you can use qx.lang.Function.bind to set the context
>> of your validator function.
>>
>
> And if you find yourself using the static method qx.lang.Function.bind(...)
> a lot and would prefer to be able to just say this.bind(...) you use this
> code in your applicaiton:
>
>      // Add a bindTo() method to qx.core.Object as a shortcut to constantly
>      // having to use qx.lang.Function.bind()
>      qx.Class.include(qx.core.Object, custom.MObject);
>
> Here's the actual mixin to add to your project:
>
> /* ************************************************************************
>
>   Copyright:
>     2009 Derrell Lipman
>
>   License:
>     LGPL: http://www.gnu.org/licenses/lgpl.html
>     EPL: http://www.eclipse.org/org/documents/epl-v10.php
>     See the LICENSE file in the project's top-level directory for details.
>
>   Authors:
>     * Derrell Lipman (derrell)
>
> ************************************************************************ */
>
> /**
> * Mixin to add a bindTo method to qx.core.Object
> */
> qx.Mixin.define("custom.MObject",
> {
>  members :
>  {
>    /**
>     * Bind a function to this object
>     *
>     * @param func {Function}
>     *   The function to be bound
>     *
>     * @param varargs {Any?}
>     *   Optional arguments to be passed to the function.
>     *
>     * @return {Function}
>     *   A wrapped version of the function that binds 'this' to the
>     *   user-provided function.
>     */
>    bindTo : function(func, varargs)
>    {
>      return qx.lang.Function.create(
>        func,
>        {
>          self  : this,
>          args  : (arguments.length > 1
>                   ? qx.lang.Array.fromArguments(arguments, 1) :
>                   null)
>        });
>    }
>  }
> });
>

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Derrell Lipman
On Tue, May 18, 2010 at 16:08, Fritz Zaucker <[hidden email]> wrote:
Hi Derrell,

wouldn't it make sense to ask for addition of this directly to the
qx.core.Object? Or to at least add your mixin to the standard distribution?

I suggested initially to add it directly to qx.core.Object. Fabian's argument against that was that Object should be kept as small as possible, given that everything descends from it. It's a valid argument, although I suspect there is other stuff that I'd exclude from Object before I'd exclude this method. In any case, I could certainly add it as an available mixin. Why don't you create an enhancement ticket and assign it to me. I'll take care of it.

Cheers,

Derrell


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
On Tue, 18 May 2010, Derrell Lipman wrote:

> On Tue, May 18, 2010 at 16:08, Fritz Zaucker <[hidden email]> wrote:
>
>> Hi Derrell,
>>
>> wouldn't it make sense to ask for addition of this directly to the
>> qx.core.Object? Or to at least add your mixin to the standard distribution?
>>
>
> I suggested initially to add it directly to qx.core.Object. Fabian's
> argument against that was that Object should be kept as small as possible,
> given that everything descends from it. It's a valid argument, although I
> suspect there is other stuff that I'd exclude from Object before I'd exclude
> this method. In any case, I could certainly add it as an available mixin.
> Why don't you create an enhancement ticket and assign it to me. I'll take
> care of it.

Cool. It's bug 3721.

Cheers,
Fritz

P.S.: I don't understand mixin's well enough, so this might be a silly
       question: if I use it in my application, then the method is added to
       every object in my application? Or could a mixin just have a "local"
       effect on the objects of a specific class (e.g., only in those
       classes, where I have a need for bind())?

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Derrell Lipman
On Wed, May 19, 2010 at 14:00, Fritz Zaucker <[hidden email]> wrote:
P.S.: I don't understand mixin's well enough, so this might be a silly
      question: if I use it in my application, then the method is added to
      every object in my application? Or could a mixin just have a "local"
      effect on the objects of a specific class (e.g., only in those
      classes, where I have a need for bind())?

A mixin has an effect on every object of the class to which it is "mixed in", including every object which descends from that class. Since nearly every class in qooxdoo descends from qx.core.Object, any methods mixed in to qx.core.Object are included in nearly every qooxdoo object. That's why Fabian's point has merit.

Hope that makes it clear.

Cheers,

Derrell


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
On Wed, 19 May 2010, Derrell Lipman wrote:

> On Wed, May 19, 2010 at 14:00, Fritz Zaucker <[hidden email]> wrote:
>
>> P.S.: I don't understand mixin's well enough, so this might be a silly
>>       question: if I use it in my application, then the method is added to
>>       every object in my application? Or could a mixin just have a "local"
>>       effect on the objects of a specific class (e.g., only in those
>>       classes, where I have a need for bind())?
>>
>
> A mixin has an effect on every object of the class to which it is "mixed
> in", including every object which descends from that class. Since nearly
> every class in qooxdoo descends from qx.core.Object, any methods mixed in to
> qx.core.Object are included in nearly every qooxdoo object. That's why
> Fabian's point has merit.

That I understand. What I am wondering is, if I could in own of my own class
files (e.g. extending qx.ui.toolbar.Toolbar) instead of

       qx.Class.include(qx.core.Object, custom.MObject);

use

       qx.Class.include(qx.ui.toolbar.Toolbar, custom.MObject);

and thus only add the bindto() method to objects descending of Toolbar. If
this could be done with the same (or somehow generic) mixin, it would give
me all control about where to use this convenience method (without
explicitely defining it myself in each class I want to use it in, which I
could, I guess?).

Cheers,
Fritz

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Derrell Lipman
On Wed, May 19, 2010 at 14:19, Fritz Zaucker <[hidden email]> wrote:
On Wed, 19 May 2010, Derrell Lipman wrote:

> On Wed, May 19, 2010 at 14:00, Fritz Zaucker <[hidden email]> wrote:
>
>> P.S.: I don't understand mixin's well enough, so this might be a silly
>>       question: if I use it in my application, then the method is added to
>>       every object in my application? Or could a mixin just have a "local"
>>       effect on the objects of a specific class (e.g., only in those
>>       classes, where I have a need for bind())?
>>
>
> A mixin has an effect on every object of the class to which it is "mixed
> in", including every object which descends from that class. Since nearly
> every class in qooxdoo descends from qx.core.Object, any methods mixed in to
> qx.core.Object are included in nearly every qooxdoo object. That's why
> Fabian's point has merit.

That I understand. What I am wondering is, if I could in own of my own class
files (e.g. extending qx.ui.toolbar.Toolbar) instead of

      qx.Class.include(qx.core.Object, custom.MObject);

use

      qx.Class.include(qx.ui.toolbar.Toolbar, custom.MObject);

and thus only add the bindto() method to objects descending of Toolbar. If
this could be done with the same (or somehow generic) mixin, it would give
me all control about where to use this convenience method (without
explicitely defining it myself in each class I want to use it in, which I
could, I guess?).

Absolutely. If you only need it with a small number of classes, that's a good way to go.

Derrell


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
On Wed, 19 May 2010, Derrell Lipman wrote:

> On Wed, May 19, 2010 at 14:19, Fritz Zaucker <[hidden email]> wrote:
>
>> On Wed, 19 May 2010, Derrell Lipman wrote:
>>
>>> On Wed, May 19, 2010 at 14:00, Fritz Zaucker <[hidden email]> wrote:
>>>
>>>> P.S.: I don't understand mixin's well enough, so this might be a silly
>>>>       question: if I use it in my application, then the method is added
>>>>       to every object in my application? Or could a mixin just have a
>>>>       "local" effect on the objects of a specific class (e.g., only in
>>>>       those classes, where I have a need for bind())?
>>>
>>> A mixin has an effect on every object of the class to which it is "mixed
>>> in", including every object which descends from that class. Since nearly
>>> every class in qooxdoo descends from qx.core.Object, any methods mixed
>>> in to qx.core.Object are included in nearly every qooxdoo object. That's
>>> why Fabian's point has merit.
>>
>> That I understand. What I am wondering is, if I could in own of my own
>> class files (e.g. extending qx.ui.toolbar.Toolbar) instead of
>>
>>       qx.Class.include(qx.core.Object, custom.MObject);
>>
>> use
>>
>>       qx.Class.include(qx.ui.toolbar.Toolbar, custom.MObject);
>>
>> and thus only add the bindto() method to objects descending of Toolbar. If
>> this could be done with the same (or somehow generic) mixin, it would give
>> me all control about where to use this convenience method (without
>> explicitely defining it myself in each class I want to use it in, which I
>> could, I guess?).
>
> Absolutely. If you only need it with a small number of classes, that's a
> good way to go.

Cool.

Now, if this would also be possible ....

  qx.Class.define("my.classA", {
      extend : qx.ui.window.Window,
   construct : function() {
        this.base(arguments);
        qx.Class.include(my.classA, my.UtilMixin);

... I'd have a generic "include" mechanism for my own classes. But I fear
that my.classA would first have to be completely defined, before the mixin
can happen?

Cheers,
Fritz (just dreaming a bit)

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

Derrell Lipman

Cool.

Now, if this would also be possible ....

 qx.Class.define("my.classA", {
     extend : qx.ui.window.Window,
  construct : function() {
       this.base(arguments);
       qx.Class.include(my.classA, my.UtilMixin);

... I'd have a generic "include" mechanism for my own classes. But I fear
that my.classA would first have to be completely defined, before the mixin
can happen?

Stop dreaming. You can do exactly that. Or, how about:

  qx.Class.define("my.classA", {
     extend : qx.ui.window.Window,
     include : [my.UtilMixin],
     ...

That should work fine, I think, although I've never tried it that way. Mixins are included all over the core code that way.

Derrell


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
lcf
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

lcf
It works so perfectly. Not even necessary an array if it's just one mixin. Like here is one of mine:

qx.Class.define("desktopforum.view.ForumsList",
{
  extend : qx.ui.form.List,

  include : desktopforum.view.ControlledView,

  construct : function()
  {
    // Configuring the window
    this.set({width: 300, height: 300});
    
    // View <=> Controller
    this.getController().setTarget(this);
  }
});


On Wed, May 19, 2010 at 10:38 PM, Derrell Lipman <[hidden email]> wrote:

Cool.

Now, if this would also be possible ....

 qx.Class.define("my.classA", {
     extend : qx.ui.window.Window,
  construct : function() {
       this.base(arguments);
       qx.Class.include(my.classA, my.UtilMixin);

... I'd have a generic "include" mechanism for my own classes. But I fear
that my.classA would first have to be completely defined, before the mixin
can happen?

Stop dreaming. You can do exactly that. Or, how about:

  qx.Class.define("my.classA", {
     extend : qx.ui.window.Window,
     include : [my.UtilMixin],
     ...

That should work fine, I think, although I've never tried it that way. Mixins are included all over the core code that way.

Derrell


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel




--
Alexander Steshenko | http://lcf.name


------------------------------------------------------------------------------


_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
In reply to this post by Derrell Lipman
On Wed, 19 May 2010, Derrell Lipman wrote:

>> Cool.
>>
>> Now, if this would also be possible ....
>>
>>  qx.Class.define("my.classA", {
>>      extend : qx.ui.window.Window,
>>   construct : function() {
>>        this.base(arguments);
>>        qx.Class.include(my.classA, my.UtilMixin);
>>
>> ... I'd have a generic "include" mechanism for my own classes. But I fear
>> that my.classA would first have to be completely defined, before the mixin
>> can happen?
>>
>
> Stop dreaming. You can do exactly that. Or, how about:
>
>  qx.Class.define("my.classA", {
>     extend : qx.ui.window.Window,
>     include : [my.UtilMixin],

Much nicer ... I guess I should read more framework code ...

> That should work fine, I think, although I've never tried it that way.
> Mixins are included all over the core code that way.

Aren't I impressed!

Thanks once more,
Fritz

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: passing context to form validation callbacks

fritz
In reply to this post by lcf
Hi Alexander,

thanks to you as well.

Cheers,
Fritz

On Wed, 19 May 2010, Alexander Steshenko wrote:

> It works so perfectly. Not even necessary an array if it's just one mixin.
> Like here is one of mine:
>
> qx.Class.define("desktopforum.view.ForumsList",
> {
>  extend : qx.ui.form.List,
>
>  include : desktopforum.view.ControlledView,
>
>  construct : function()
>  {
>    // Configuring the window
>    this.set({width: 300, height: 300});
>
>    // View <=> Controller
>    this.getController().setTarget(this);
>  }
> });
>
>
> On Wed, May 19, 2010 at 10:38 PM, Derrell Lipman <
> [hidden email]> wrote:
>
>>
>> Cool.
>>>
>>> Now, if this would also be possible ....
>>>
>>>  qx.Class.define("my.classA", {
>>>      extend : qx.ui.window.Window,
>>>   construct : function() {
>>>        this.base(arguments);
>>>        qx.Class.include(my.classA, my.UtilMixin);
>>>
>>> ... I'd have a generic "include" mechanism for my own classes. But I fear
>>> that my.classA would first have to be completely defined, before the mixin
>>> can happen?
>>>
>>
>> Stop dreaming. You can do exactly that. Or, how about:
>>
>>   qx.Class.define("my.classA", {
>>      extend : qx.ui.window.Window,
>>      include : [my.UtilMixin],
>>      ...
>>
>> That should work fine, I think, although I've never tried it that way.
>> Mixins are included all over the core code that way.
>>
>> Derrell
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>>
>> _______________________________________________
>> qooxdoo-devel mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>>
>>
>
>
>

--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel