Quantcast

How can I get the object descriptor for a Dojo node set with data-dojo-attach-point?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How can I get the object descriptor for a Dojo node set with data-dojo-attach-point?

Jorge Nelson Pinheiro Goncalves Teixeira
Hello all,

In one of my templates I have the following node:

<input data-dojo-attach-point="checkboxIsInternal" type="checkbox" checked />

I want to change the value of another property in the template's class to a certain value when this check is changed. So I thought in modifying the getter and setter for checkboxIsInternal's 'value' property so this happens automatically. Like this:

Object.defineProperty(this.checkboxIsInternal, 'value', {
    get: function() { return (this.clientType == 'I'); },
    set: function(v) { this.clientType = (v == 'on' ? 'I' : 'E'); },
    enumerable: true
});

but this hasn't worked. So I tried to console.log the descriptors of value property with

console.log(Object.getOwnPropertyDescriptor(this.checkboxIsInternal, 'value'));

but it showed undefined. Anyone knows why ?


--
Nelson Teixeira
blog:www.ideiassobrecodigo.com.br


-


"Esta mensagem do SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), empresa pública federal regida pelo disposto na Lei Federal nº 5.615, é enviada exclusivamente a seu destinatário e pode conter informações confidenciais, protegidas por sigilo profissional. Sua utilização desautorizada é ilegal e sujeita o infrator às penas da lei. Se você a recebeu indevidamente, queira, por gentileza, reenviá-la ao emitente, esclarecendo o equívoco."

"This message from SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO) -- a government company established under Brazilian law (5.615/70) -- is directed exclusively to its addressee and may contain confidential data, protected under professional secrecy rules. Its unauthorized use is illegal and may subject the transgressor to the law's penalties. If you're not the addressee, please send it back, elucidating the failure."

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How can I get the object descriptor for a Dojo node set with data-dojo-attach-point?

dylanks
Hi Jorge,

Historically, tightly coupling domNodes and JS properties was a recipe
for memory leaks in IE, so that is not how Dijit was designed.

The better approaches to take would be to either define the event
handler in the widget constructor, or with a reference to the widget itself.

1. In your widget instance you can define event handlers for the
widget's click handler
2. With a reference to the widget, you can define event handlers. You
can either get a reference to a widget via the return value of when you
instantiate it via JavaScript, or by looking it up via dijit/registry

https://dojotoolkit.org/documentation/tutorials/1.10/checkboxes/index.html
probably contains enough details on what you're looking for, but if not,
please ask a follow-up question if you're still stuck.

Regards,
-Dylan

on 1/20/17, 09:26 (GMT-07:00) Jorge Nelson Pinheiro Goncalves Teixeira
said the following:

> Hello all,
>
> In one of my templates I have the following node:
>
> |<input data-dojo-attach-point="checkboxIsInternal" type="checkbox" checked />|
>
> I want to change the value of another property in the template's class
> to a certain value when this check is changed. So I thought in modifying
> the getter and setter for checkboxIsInternal's 'value' property so this
> happens automatically. Like this:
>
> |Object.defineProperty(this.checkboxIsInternal, 'value', {
>     get: function() { return (this.clientType == 'I'); },
>     set: function(v) { this.clientType = (v == 'on' ? 'I' : 'E'); },
>     enumerable: true
> });|
>
> but this hasn't worked. So I tried to console.log the descriptors of
> value property with
>
> |console.log(Object.getOwnPropertyDescriptor(this.checkboxIsInternal, 'value'));|
>
> but it showed undefined. Anyone knows why ?
>
>
> --
> Nelson Teixeira
> [hidden email]
> blog:www.ideiassobrecodigo.com.br
>
> -
>
>
> "Esta mensagem do SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
> empresa pública federal regida pelo disposto na Lei Federal nº 5.615, é
> enviada exclusivamente a seu destinatário e pode conter informações
> confidenciais, protegidas por sigilo profissional. Sua utilização
> desautorizada é ilegal e sujeita o infrator às penas da lei. Se você a
> recebeu indevidamente, queira, por gentileza, reenviá-la ao emitente,
> esclarecendo o equívoco."
>
> "This message from SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO) --
> a government company established under Brazilian law (5.615/70) -- is
> directed exclusively to its addressee and may contain confidential data,
> protected under professional secrecy rules. Its unauthorized use is
> illegal and may subject the transgressor to the law's penalties. If
> you're not the addressee, please send it back, elucidating the failure."
>
--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Co-Founder, Dojo Toolkit
CEO, SitePen, Inc.  http://www.sitepen.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How can I get the object descriptor for a Dojo node set with data-dojo-attach-point?

Jorge Nelson Pinheiro Goncalves Teixeira
Great Dylan. Thanks for your help. Solved my problem. :)

Nelson Teixeira

Em 21/01/2017 09:26:50, Dylan Schiemann escreveu:
Hi Jorge,

Historically, tightly coupling domNodes and JS properties was a recipe
for memory leaks in IE, so that is not how Dijit was designed.

The better approaches to take would be to either define the event
handler in the widget constructor, or with a reference to the widget itself.

1. In your widget instance you can define event handlers for the
widget's click handler
2. With a reference to the widget, you can define event handlers. You
can either get a reference to a widget via the return value of when you
instantiate it via JavaScript, or by looking it up via dijit/registry

https://dojotoolkit.org/documentation/tutorials/1.10/checkboxes/index.html
probably contains enough details on what you're looking for, but if not,
please ask a follow-up question if you're still stuck.

Regards,
-Dylan

on 1/20/17, 09:26 (GMT-07:00) Jorge Nelson Pinheiro Goncalves Teixeira
said the following:
> Hello all,
> 
> In one of my templates I have the following node:
> 
> ||
> 
> I want to change the value of another property in the template's class
> to a certain value when this check is changed. So I thought in modifying
> the getter and setter for checkboxIsInternal's 'value' property so this
> happens automatically. Like this:
> 
> |Object.defineProperty(this.checkboxIsInternal, 'value', {
>     get: function() { return (this.clientType == 'I'); },
>     set: function(v) { this.clientType = (v == 'on' ? 'I' : 'E'); },
>     enumerable: true
> });|
> 
> but this hasn't worked. So I tried to console.log the descriptors of
> value property with
> 
> |console.log(Object.getOwnPropertyDescriptor(this.checkboxIsInternal, 'value'));|
> 
> but it showed undefined. Anyone knows why ?
> 
> 
> -- 
> Nelson Teixeira
> [hidden email]
> blog:www.ideiassobrecodigo.com.br
> 
> -
> 
> 
> "Esta mensagem do SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
> empresa pública federal regida pelo disposto na Lei Federal nº 5.615, é
> enviada exclusivamente a seu destinatário e pode conter informações
> confidenciais, protegidas por sigilo profissional. Sua utilização
> desautorizada é ilegal e sujeita o infrator às penas da lei. Se você a
> recebeu indevidamente, queira, por gentileza, reenviá-la ao emitente,
> esclarecendo o equívoco."
> 
> "This message from SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO) --
> a government company established under Brazilian law (5.615/70) -- is
> directed exclusively to its addressee and may contain confidential data,
> protected under professional secrecy rules. Its unauthorized use is
> illegal and may subject the transgressor to the law's penalties. If
> you're not the addressee, please send it back, elucidating the failure."
> 
-- 
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

-


"Esta mensagem do SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), empresa pública federal regida pelo disposto na Lei Federal nº 5.615, é enviada exclusivamente a seu destinatário e pode conter informações confidenciais, protegidas por sigilo profissional. Sua utilização desautorizada é ilegal e sujeita o infrator às penas da lei. Se você a recebeu indevidamente, queira, por gentileza, reenviá-la ao emitente, esclarecendo o equívoco."

"This message from SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO) -- a government company established under Brazilian law (5.615/70) -- is directed exclusively to its addressee and may contain confidential data, protected under professional secrecy rules. Its unauthorized use is illegal and may subject the transgressor to the law's penalties. If you're not the addressee, please send it back, elucidating the failure."

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Loading...