Project

General

Profile

Bug #4512

JQuery event handlers stop working after widget reparenting

Added by Alan Finley over 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
10/15/2015
Due date:
% Done:

0%

Estimated time:

Description

Here's a minimal example:

void reparent(WText *t, WContainerWidget *oldP, WContainerWidget *newP);
void click_slot();

Wt::WApplication* createApplication(const Wt::WEnvironment& env)
{
    WApplication *app = new WApplication(env);

    WContainerWidget *c = new WContainerWidget(app->root());
    WPushButton *b = new WPushButton("Reparent", c);
    WText *t = new WText(c);
    t->setText(WString("My id is: {1}").arg(t->jsRef()));
    t->clicked().connect(boost::bind(&click_slot));
    t->doJavaScript("$(" + t->jsRef() + ").click(function() { console.log('click'); } )");

    WContainerWidget *c2 = new WContainerWidget(app->root());

    b->clicked().connect(boost::bind(&reparent, t, c, c2));

    return app;
}

void reparent(WText *t, WContainerWidget *oldP, WContainerWidget *newP)
{
    oldP->removeWidget(t);
    newP->addWidget(t);

    WString oldString = t->text();
    oldString += WString(". My new id is: {1}").arg(t->jsRef());
    t->setText(oldString);
}

void click_slot()
{
    std::cout << "CLICK!" << std::endl;
}

I create a WText widget and then attach a C event hadler to the clicked signal and also attach a JQuery handler for js click signal. Both handlers work fine. I can see debug output both in app console and browser console.

But when I reparent the widget, JQuery handler is not called anymore.

#1

Updated by Koen Deforche about 6 years ago

  • Status changed from New to Resolved
  • Assignee set to Koen Deforche
  • Target version changed from 3.3.1 to 3.3.5

This no longer seems to be an issue with current git, I'm not sure though when we solved this.

#2

Updated by Koen Deforche about 6 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF