Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return HTML from hooks to self-replace. #214

Closed
romaninsh opened this issue Aug 24, 2017 · 4 comments
Closed

Return HTML from hooks to self-replace. #214

romaninsh opened this issue Aug 24, 2017 · 4 comments

Comments

@romaninsh
Copy link
Member

$b = new Button();
$app->add($b);

$b->onClick(function() use($b) {
    return $b->addClass('red');
});

When button is clicked it should replace itself with new provided HTML.

@DarkSide666
Copy link
Member

DarkSide666 commented Aug 26, 2017

return $b->addClass('red'); is not HTML, but object.
Not sure yet if this will be good or bad. Why self-replacing is something different than doing any other action on other views trough hooks?

@romaninsh
Copy link
Member Author

You could replace form with message.

@DarkSide666
Copy link
Member

Isn't something like this already working?

$b = new Button();
$f = new Form();
$app->add($b);
$app->add($f);

$b->onClick(function($b) use ($f) {
    $b->addClass('red')->set('Thanks for clicking'); // change button
    $f->destroy(); // no more form at all
});

but, yeah, i guess you're right - we probably need to return HTML code (or renderable object) and that could replace object on which hook is called. In this case - button. Otherwise we have to use JS chain to make some changes in layout.

@romaninsh
Copy link
Member Author

partially resolved in #179

@mvorisek mvorisek closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants