M
M
Maybe_V2016-06-15 00:10:47
JavaScript
Maybe_V, 2016-06-15 00:10:47

How to correctly save data to the buffer from the fields?

There is a GridView in which it is displayed using a function for each input line and a button, when pressed, the input content should be saved to the buffer. To do this, I use the clipboard.js
library , I do everything according to the instructions, and it really works, but there are a couple of bugs (one bug is of the library itself, and the other, apparently, is mine):

  1. does not copy content with an input whose disabled property is set to false.
  2. the content is copied, always only the first input.

This is how I implement the GridView and widget to display input:
GridView:
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            [
                'attribute' => 'file',
                'format' => 'raw',
                'label' => 'File',
                'value' =>  function($data){
                    return FileManagerInputWidget::widget([
                        'path' =>  Url::to('@fileManager/'.$data['file']),
                    ]);
                }
            ]);
 ?>

FileManagerInputWidget:
<?php

namespace common\widgets;


use yii\base\Widget;

class FileManagerInputWidget extends Widget
{
    public $path;
    
    function init()
    {
       
    }
    
    function run()
    {
       return $this->render('file-manager-input',[
        'path' =>  $this->path,
       ]);
    }

  
}

file-manager-input.php
<?php
use yii\helpers\Html;
use yii\web\AssetBundle;
use yii\web\View;
/**
 * @var $this View
 * */
AssetBundle::register($this);
$this->beginPage();
?>

<!DOCTYPE html>
<html>
<head>
    <?php
        $this->head();
    ?>
    <?php $this->registerJs('(function(){
        new Clipboard(\'#copy\');
    })();')?>

</head>
<body>
<?php $this->beginBody()?>

<div class="row">
    <div class="col-lg-6">
        <div class="input-group">
            <?= Html::input('text', null ,$path,
                [
                    'class'=> 'form-control',
                    'id' => 'link',
                ])
            ?>
                <span class="input-group-btn">
             <?= Html::button('Copy',
                 [
                     'id' => 'copy',
                     'class' => 'btn btn-default',
                     'data-clipboard-target' => '#link',
                 ])?>
      </span>
        </div>
    </div>
</div>

<?php $this->endBody()?>
</body>
</html>
<?php
$this->endPage();
?>

Copying is, but copies only from the very first input.
How can this be fixed?
I thought it was due to the fact that I implement the output of inputs and buttons in the GridView in this way, but I did it differently and this bug remained!
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
polar-bear, 2016-06-15
@polar-bear

You set the plugin to id, and therefore copies from the first id encountered on the page. Try it through the class

<?php $this->registerJs('(function(){
        new Clipboard(\'.copy\');
    })();')?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question