On Wed, Mar 5, 2008 at 7:26 AM, Ales Rippl <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> let me bring already discussed topic on again.
> I would like to override generated property.
>
> ...
>
> This is for special cases where I extend b.form.TextField in class
> b.form.MoneyTextField
> where I want to do:
>
> setValue : function(value) {
> this.base(arguments, formatForDisplay(value));
> },
> getValue : function() {
> return this.base(asrguments, formatForStore(value));
> }
>
> and it is not possible.
It is very unfortunate that one is not allowed to override a property.
It "should" be possible with a Mixin and qx.Class.patch(), but even
there, where it is expected that the caller knows exactly what he's
doing, it's not allowed to override a property.
What you're looking for, however, is the "transform" key. You can
accomplish part of what you're looking for by doing (the setter
portion) by doing something like this:
In your class that extends TextField, add a new property, say monetaryValue:
properties :
{
monetaryValue :
{
transform : "formatForDisplay"
}
}
The transform key of monetaryValue causes the specified function,
formatForDisplay, to be called when setMonetaryValue() is called.
formatForDisplay is expected to take one parameter, the value being
set, and return the transformed value to be saved. If
formatForDisplay decides that the value that was passed to it is
invalid (e.g. the string "abc" instead of the number 23.42) it should
throw an error.
That doesn't help your getter, though.
Another option is to not add a monetaryValue property and instead add
a new method:
getMonetaryValue : function()
{
return formatForDisplay(getValue());
}
That way, the 'value' property always contains the "native" value and
you can obtain the properly formatted version with getMonetaryValue().
(Then again, if you do this, you could as easily just format the
value at the time you're displaying it.)
Add your vote for properties being patchable! There's no reason I can
see that it should be disallowed other than emotional ones. This
topic comes up ever few months with someone needing this capability.
Cheers,
Derrell
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel