Answer the question
In order to leave comments, you need to log in
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):
<?= 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']),
]);
}
]);
?>
<?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,
]);
}
}
<?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();
?>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question