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

Snippet redraw not working with BootstrapRenderer #10

Open
Mirovsky opened this issue Apr 14, 2016 · 3 comments
Open

Snippet redraw not working with BootstrapRenderer #10

Mirovsky opened this issue Apr 14, 2016 · 3 comments
Labels

Comments

@Mirovsky
Copy link

When used any of BootstrapRenderers, snippet redraw sends the message but actual redraw never happens.

Presenter:

class SimplePresenter extends Nette\Application\UI\Presenter {
    public function createComponentSimpleForm() {
        $form = new Nette\Application\UI\Form();
        $form->setRenderer(new BootstrapRenderer);
        $form->getElementPrototype()->class('ajax');

        $form->addText('text', 'Text');
        $form->addSubmit('submit', 'Submit');

        $form->onSuccess[] = array($this, 'onSuccess');

        return $form;
    }
    public function onSuccess(Nette\Application\UI\Form $form) {
        $form->setValues(array(), TRUE);
        $this->redrawControl('form');
    }
}

Template:

{block content}

    {snippet form}
        {control simpleForm}
    {/snippet}

{/block}

All files are included, $.nette.init() called, other snippets redraws are working.
After commenting out line with $form->setRenderer(...) its works properly. Also when DefaultFormRenderer is used, everything works as expected.

@tomaj tomaj added the bug label Apr 18, 2016
@tomaj
Copy link
Owner

tomaj commented Apr 18, 2016

Can you send some error message that you get? or maybe whole presenter file?

@Mirovsky
Copy link
Author

There is no error message. And the whole presenter file looks like this.

<?php

namespace App\Modules\Admin\Presenters;

use Nette;
use Tomaj\Form\Renderer\BootstrapRenderer;

class SimplePresenter extends Nette\Application\UI\Presenter {

    public function createComponentSimpleForm() {
        $form = new Nette\Application\UI\Form();
        $form->setRenderer(new BootstrapRenderer);
        $form->getElementPrototype()->class('ajax');

        $form->addText('text', 'Text');
        $form->addSubmit('submit', 'Submit');

        $form->onSuccess[] = array($this, 'onSuccess');

        return $form;
    }
    public function onSuccess(Nette\Application\UI\Form $form) {
        $form->setValues(array(), TRUE);
        $this->redrawControl('form');
    }

}

and for template

{**
 * @param string   $basePath web base path
 * @param array    $flashes  flash messages
 *}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <title>{ifset title}{include title|striptags} | {/ifset}Nette Sandbox</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="{$basePath}/css/style.css">
    <meta name="viewport" content="width=device-width">
    {block head}{/block}
</head>

<body>
    <div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>

    <div class="container">
       {snippet form}
          {control simpleForm}
       {/snippet}
    </div>

    {block scripts}
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="{$basePath}/bower_components/nette.ajax.js/nette.ajax.js"></script>
    <script src="{$basePath}/js/main.js"></script>
    {/block}
</body>
</html>

and inside main.js is only this:

$(function () {
    $.nette.init();
});

and this is what i get inside the response from server:

{state: [], snippets: {,…}}
snippets: {,…}
snippet--form: "<form action="/admin/simple/default" method="post" class="ajax form-horizontal" id="frm-simpleForm" novalidate="novalidate">↵↵<div>↵<div class="form-group">↵   <div class="col-sm-3 control-label"><label for="frm-simpleForm-text">Text</label></div>↵↵   <div class="col-sm-9"><input type="text" name="text" class="form-control text" id="frm-simpleForm-text"></div>↵</div>↵↵<div class="form-group">↵    <div class="col-sm-3 control-label"></div>↵↵    <div class="col-sm-9"><input type="submit" name="_submit" class="btn btn-primary button" value="Submit"></div>↵</div>↵</div>↵↵<div><input type="hidden" name="do" value="simpleForm-submit"><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>↵</form>↵"
state: []

@SimeonAnunciado
Copy link

There is no error message. And the whole presenter file looks like this.

<?php

namespace App\Modules\Admin\Presenters;

use Nette;
use Tomaj\Form\Renderer\BootstrapRenderer;

class SimplePresenter extends Nette\Application\UI\Presenter {

    public function createComponentSimpleForm() {
        $form = new Nette\Application\UI\Form();
        $form->setRenderer(new BootstrapRenderer);
        $form->getElementPrototype()->class('ajax');

        $form->addText('text', 'Text');
        $form->addSubmit('submit', 'Submit');

        $form->onSuccess[] = array($this, 'onSuccess');

        return $form;
    }
    public function onSuccess(Nette\Application\UI\Form $form) {
        $form->setValues(array(), TRUE);
        $this->redrawControl('form');
    }

}

and for template

{**
 * @param string   $basePath web base path
 * @param array    $flashes  flash messages
 *}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <title>{ifset title}{include title|striptags} | {/ifset}Nette Sandbox</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="{$basePath}/css/style.css">
    <meta name="viewport" content="width=device-width">
    {block head}{/block}
</head>

<body>
    <div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>

    <div class="container">
       {snippet form}
          {control simpleForm}
       {/snippet}
    </div>

    {block scripts}
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="{$basePath}/bower_components/nette.ajax.js/nette.ajax.js"></script>
    <script src="{$basePath}/js/main.js"></script>
    {/block}
</body>
</html>

and inside main.js is only this:

$(function () {
    $.nette.init();
});

and this is what i get inside the response from server:

{state: [], snippets: {,…}}
snippets: {,…}
snippet--form: "<form action="/admin/simple/default" method="post" class="ajax form-horizontal" id="frm-simpleForm" novalidate="novalidate">↵↵<div>↵<div class="form-group">↵   <div class="col-sm-3 control-label"><label for="frm-simpleForm-text">Text</label></div>↵↵   <div class="col-sm-9"><input type="text" name="text" class="form-control text" id="frm-simpleForm-text"></div>↵</div>↵↵<div class="form-group">↵    <div class="col-sm-3 control-label"></div>↵↵    <div class="col-sm-9"><input type="submit" name="_submit" class="btn btn-primary button" value="Submit"></div>↵</div>↵</div>↵↵<div><input type="hidden" name="do" value="simpleForm-submit"><!--[if IE]><input type=IEbug disabled style="display:none"><![endif]--></div>↵</form>↵"
state: []

im encountering this how do you fix this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants