kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
http://demos.krajee.com/markdown
Other
89 stars 41 forks source link

MarkdownEditor does not work when load via Boostrap modal #11

Closed thanh-vinh closed 10 years ago

thanh-vinh commented 10 years ago

I use a Boostrap Modal to load the comment view remote which provided by another controller, but the toolbar does not work. A java script error message show each time a toolbar button is clicked.

Uncaught TypeError: Cannot read property 'length' of undefined VM728:152
    markUp VM728:152
    onclick

The error line:

function markUp(btn, source) {
    var el = $(source)
    el.focus();
    var txt = el.extractSelectedText(),
        len = txt.length, //!!! throw the exception above
        str = txt

    // Bold
    if (btn == 1) {
        str = (txt.length > 0) ? getBlockMarkUp(txt, '**', '**') : '**(bold text here)**';
    }
...

Views The Modal in the caller controller:

Modal::begin([
    'id' => 'delete-modal',
    'clientOptions' => [
        'modal' => true,
        'autoOpen' => false,
        'remote' => 'the remote content that has the MarkdownEditor widget'
    ],
]);
Modal::end();

And, the MarkdownEditor in the remote controller:

<?= MarkdownEditor::widget([
    'name' => 'task-comment',
    'height' => 80,
    'encodeLabels' => true,
    'toolbar' => [
        //...
    ],
    'footerMessage' => '',
    'showExport' => false,
]) ?>
kartik-v commented 10 years ago

It seems to work for content embedded in Modal. Check the demo at http://demos.krajee.com/markdown-details/markdown-editor#editor-settings.

Can you update if you missed something in your code - or post your code gist.

thanh-vinh commented 10 years ago

I have changed my code, put the editor in a Modal of the current view instead of remote content then it works fine.

Thanks for a great widget.