Low Level Question

View: New views
3 Messages — Rating Filter:   Alert me  

Low Level Question

by Guilherme Aiolfi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm pretty sure it's simple but I not used to low level stuff. What I want to do is create a click event in the recently created button to remove its parent div:

        qx.bom.Collection.query("#add_category_button").addListener("click", function(e)
        {
             var html = "<div class='category'><input name='cat[name]'/><input class='category_remove_button' type='button' value='remover' /></div>";
             e.preventDefault();
             qx.bom.Collection.create(e.getTarget()).before(html); // is there a cleaver way to do that?
             return false;
        }, this);

Adding:
  qx.bom.Collection.query(".category_remove_button").addListener("click", function(e) { }, this);

doesn't help because the element is not created yet.


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: Low Level Question

by Alexander Steitz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Guilherme,

On Wednesday 04 November 2009 Guilherme Aiolfi wrote:

> I'm pretty sure it's simple but I not used to low level stuff. What I want
> to do is create a click event in the recently created button to remove its
> parent div:
>
>         qx.bom.Collection.query("#add_category_button").addListener("click"
> , function(e)
>         {
>              var html = "<div class='category'><input
> name='cat[name]'/><input class='category_remove_button' type='button'
> value='remover' /></div>";
>              e.preventDefault();
>              qx.bom.Collection.create(e.getTarget()).before(html); // is
> there a cleaver way to do that?
>              return false;
>         }, this);
>
> Adding:
>   qx.bom.Collection.query(".category_remove_button").addListener("click",
> function(e) { }, this);
>
> doesn't help because the element is not created yet.
I think a possible solution can be to create the collection inside the
listener method and directly add the listener there.

--snip--
// instead of
qx.bom.Collection.create(e.getTarget()).before(html);

// write
var html = qx.bom.Collection.html("<div class='category'><input
name='cat[name]'/><input class='category_remove_button' type='button'
value='remover' /></div>");

qx.bom.Collection.create(e.getTarget()).before(html[0]);

html.find(".category_remove_button").addListener("click", function(e) {});
--snip--

This way you have the inserted HTML as collection and you should be able to
add a listener to it.

I hope this works - I have not tested this code.

cheers,
  Alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Re: Low Level Question

by Guilherme Aiolfi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alexander,

That worked. Thank you.

On Wed, Nov 4, 2009 at 1:14 PM, Alexander Steitz <alexander.steitz@...> wrote:
Hi Guilherme,

On Wednesday 04 November 2009 Guilherme Aiolfi wrote:
> I'm pretty sure it's simple but I not used to low level stuff. What I want
> to do is create a click event in the recently created button to remove its
> parent div:
>
>         qx.bom.Collection.query("#add_category_button").addListener("click"
> , function(e)
>         {
>              var html = "<div class='category'><input
> name='cat[name]'/><input class='category_remove_button' type='button'
> value='remover' /></div>";
>              e.preventDefault();
>              qx.bom.Collection.create(e.getTarget()).before(html); // is
> there a cleaver way to do that?
>              return false;
>         }, this);
>
> Adding:
>   qx.bom.Collection.query(".category_remove_button").addListener("click",
> function(e) { }, this);
>
> doesn't help because the element is not created yet.
I think a possible solution can be to create the collection inside the
listener method and directly add the listener there.

--snip--
// instead of
qx.bom.Collection.create(e.getTarget()).before(html);

// write
var html = qx.bom.Collection.html("<div class='category'><input
name='cat[name]'/><input class='category_remove_button' type='button'
value='remover' /></div>");

qx.bom.Collection.create(e.getTarget()).before(html[0]);

html.find(".category_remove_button").addListener("click", function(e) {});
--snip--

This way you have the inserted HTML as collection and you should be able to
add a listener to it.

I hope this works - I have not tested this code.

cheers,
 Alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@...
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel