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

possible javascript bug with markdown widget in detail view #26

Closed andrewblake1 closed 5 years ago

andrewblake1 commented 10 years ago

Putting the markdown editor into your detailview widget causes preview amongst other things to fail - no console error. This only happens when the export button is enabled and seems to be somehow related to the id for the iframe - altering the id prohibits jquery from selecting the iframe when it is intended hence the conflict doesn't occur - no doubt something else won't work though - probably export am guessing but haven't tried. If I place the widget outside the detail view it works, or if I place 1 outside the detail view and 1 inside, then both work.

kartik-v commented 10 years ago

How are you creating the markdown editor inside the detail view? Also, are you using any other javascript code or other jquery plugins?

I have tested the following code which works:

echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        ['attribute'=>'id', 'label'=>'Book # '],
        ['attribute'=>'buy_amount', 'format'=>'double', 'label'=>'Buy ($)'],
        [
            'attribute'=>'synopsis',
            'format'=>'raw',
            'value'=>'<span class="text-justify"><em>' . $model->synopsis . '</em></span>',
            'type'=>DetailView::INPUT_WIDGET, 
            'widgetOptions'=>[
                'class'=>\kartik\markdown\MarkdownEditor::classname(),
            ],
        ]
    ]
]);

The export function uses another internally generated form. The nested forms and identifiers could be an issue - but I need to know how you are getting the error.

andrewblake1 commented 10 years ago

jquery.js kv-detail-view.js yii.js yii.validation.js rangyinputs-jquery-1.1.2.js kv-markdown.js yii.activeForm.js bootstrap.js

<?php

use kartik\detail\DetailView;
use kartik\markdown\MarkdownEditor;

/**
 * @var yii\web\View $this
 * @var common\models\Model $model
 * @var yii\widgets\ActiveForm $form
 */
?>

<div class="model-form">

    <?= DetailView::widget([
        'model'=>$model,
        'mode'=>DetailView::MODE_EDIT,
        'attributes'=>[
            ['attribute' => 'label', 'type' => DetailView::INPUT_TEXT, 'options' => ['maxlength' => 64]],
            ['attribute' => 'label_plural', 'type' => DetailView::INPUT_TEXT, 'options' => ['maxlength' => 64]],
            ['attribute' => 'help', 'type' => DetailView::INPUT_WIDGET,
                'widgetOptions' => [
                    'class' => 'kartik\markdown\MarkdownEditor',
//                  'showExport' => false,
                ],
            ],
        ]
    ]); ?>

</div>
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.