kartik-v / yii2-editable

An enhanced editable widget for Yii 2.0 that allows easy editing of displayed data with html inputs, widgets and more.
http://demos.krajee.com/editable
Other
112 stars 55 forks source link

When using multiple editable widgets on one page, only the first one works #132

Closed TomasMolnar closed 7 years ago

TomasMolnar commented 8 years ago

Currently it is not possible to use multiple editable widgets on one page when model[attribute] mode is used. Its due to container DIV id generation bug. To fix it, you need to change the line 527 of vendor/yii2-editable/Editable.php to be like this:

$this->containerOptions['id'] = $this->getId(); //Html::get $this->options['id'] . '-cont';

baldiri commented 7 years ago

Hi @TomasMolnar,

it's enough if you use property 'id' inside 'options' property array of editable widget, like this:

Editable::widget([
      'options' => ['id' => $model->id,]
]);

I had same problem and this solved it.

Bye!

TomasMolnar commented 7 years ago

thanks @baldiri !

cavidz commented 5 years ago

Hi there! Firstly, thank you very much Kartik for all your widgets! You are amazing! And secondly, I have same error with multpile use of Editable. Here is code of my view file:

<div class="col-md-4">
       <?= Html::activeLabel($model, 'delivery_comment') ?>
        <br>
        <?= Editable::widget([
                        'model' => $model,
                        'attribute'=>'delivery_comment',
                        'inputType' => Editable::INPUT_TEXTAREA,
                        'options' => [
                            'class'=>'form-control',
                            'rows'=>5, 
                            'id' => 'form-delivery-'.$model->stor_number,
                        ],
                    ]); 
         ?>
         <?= Html::error($model, 'delivery_comment') ?>
</div>
<div class="col-md-4">
       <?= Html::activeLabel($model, 'loyality_comment') ?>
        <br>
        <?= Editable::widget([
                        'model' => $model,
                        'attribute'=>'loyality_comment',
                        'inputType' => Editable::INPUT_TEXTAREA,
                        'options' => [
                            'class'=>'form-control', 
                            'rows'=>5, 
                            'id' => 'form-loyality-'.$model->stor_number,
                        ],
                    ]); 
        ?>
        <?= Html::error($model, 'loyality_comment') ?>
</div>

As you see I added uniqe id inside options. But when I enter something only in first input(second works as I expect), I got error like:

Uncaught TypeError: elem.replace is not a function at Function.buildFragment (jquery.js:5114) at jQuery.fn.init.domManip (jquery.js:5387) at jQuery.fn.init.append (jquery.js:5218) at jQuery.fn.init. (jquery.js:5333) at jQuery.access (jquery.js:3491) at jQuery.fn.init.html (jquery.js:5300) at showError (editable.js:93) at Object.error (editable.js:168) at fire (jquery.js:3099) at Object.fireWith [as rejectWith] (jquery.js:3211)