Skip to content

Commit 494602f

Browse files
author
Eugene Tupikov
committed
refactoring
1 parent 5de6f20 commit 494602f

File tree

11 files changed

+1134
-545
lines changed

11 files changed

+1134
-545
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: unclead_2
5+
* Date: 15.08.2015
6+
* Time: 18:34
7+
*/
8+
9+
namespace unclead\widgets\examples\actions;
10+
11+
use Yii;
12+
use unclead\widgets\examples\models\Item;
13+
use yii\base\Action;
14+
use yii\base\Model;
15+
use yii\bootstrap\ActiveForm;
16+
use yii\web\Response;
17+
18+
class TabularInputAction extends Action
19+
{
20+
public function run()
21+
{
22+
Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../'));
23+
24+
$count = count(Yii::$app->request->post('Item', []));
25+
$models = [new Item()];
26+
for($i = 1; $i < $count; $i++) {
27+
$models[] = new Item();
28+
}
29+
30+
$request = Yii::$app->getRequest();
31+
if ($request->isPost && $request->post('ajax') !== null) {
32+
Model::loadMultiple($models, Yii::$app->request->post());
33+
Yii::$app->response->format = Response::FORMAT_JSON;
34+
$result = ActiveForm::validateMultiple($models);
35+
return $result;
36+
}
37+
38+
if (Model::loadMultiple($models, Yii::$app->request->post())) {
39+
// put here your logic
40+
}
41+
42+
43+
return $this->controller->render('@unclead-examples/views/tabular.php', ['models' => $models]);
44+
}
45+
}

examples/models/Item.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace unclead\widgets\examples\models;
4+
5+
use Yii;
6+
use yii\base\Model;
7+
// you have to install https://github.com/vova07/yii2-fileapi-widget
8+
use vova07\fileapi\behaviors\UploadBehavior;
9+
10+
/**
11+
* Class Item
12+
* @package unclead\widgets\examples\models
13+
*/
14+
class Item extends Model
15+
{
16+
17+
public $title;
18+
19+
public $description;
20+
21+
public $file;
22+
23+
public $date;
24+
25+
26+
public function behaviors()
27+
{
28+
return [
29+
'uploadBehavior' => [
30+
'class' => UploadBehavior::className(),
31+
'attributes' => [
32+
'file' => [
33+
'path' => Yii::getAlias('@webroot') . '/images/',
34+
'tempPath' => Yii::getAlias('@webroot') . '/images/tmp/',
35+
'url' => '/images/'
36+
],
37+
]
38+
]
39+
];
40+
}
41+
42+
public function rules()
43+
{
44+
return [
45+
[['title', 'description'], 'required']
46+
];
47+
}
48+
49+
50+
}

examples/views/example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
->label(false);
3232
?>
3333

34-
<h3>Multiple columns</h3>
34+
<h3>Multiple columns</h3>
3535
<?= $form->field($model, 'schedule')->widget(MultipleInput::className(), [
3636
'id' => 'schedule-wrapper',
3737
'limit' => 4,

examples/views/tabular.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
use yii\bootstrap\ActiveForm;
4+
use unclead\widgets\TabularInput;
5+
use yii\helpers\Html;
6+
use \unclead\widgets\examples\models\Item;
7+
8+
/* @var $this \yii\web\View */
9+
/* @var $models Item[] */
10+
?>
11+
12+
<?php $form = \yii\bootstrap\ActiveForm::begin([
13+
'id' => 'tabular-form',
14+
'enableAjaxValidation' => true,
15+
'enableClientValidation' => false,
16+
'validateOnChange' => false,
17+
'validateOnSubmit' => true,
18+
'validateOnBlur' => false,
19+
]) ?>
20+
21+
<?= TabularInput::widget([
22+
'models' => $models,
23+
'attributeOptions' => [
24+
'enableAjaxValidation' => true,
25+
'enableClientValidation' => false,
26+
'validateOnChange' => false,
27+
'validateOnSubmit' => true,
28+
'validateOnBlur' => false,
29+
],
30+
'columns' => [
31+
[
32+
'name' => 'title',
33+
'title' => 'Title',
34+
'type' => \unclead\widgets\MultipleInputColumn::TYPE_TEXT_INPUT,
35+
],
36+
[
37+
'name' => 'description',
38+
'title' => 'Description',
39+
],
40+
[
41+
'name' => 'file',
42+
'title' => 'File',
43+
'type' => \vova07\fileapi\Widget::className(),
44+
],
45+
[
46+
'name' => 'date',
47+
'type' => \kartik\date\DatePicker::className(),
48+
'title' => 'Day',
49+
'items' => [
50+
'0' => 'Saturday',
51+
'1' => 'Monday'
52+
],
53+
'options' => [
54+
'pluginOptions' => [
55+
'format' => 'dd.mm.yyyy',
56+
'todayHighlight' => true
57+
]
58+
],
59+
'headerOptions' => [
60+
'style' => 'width: 250px;',
61+
'class' => 'day-css-class'
62+
]
63+
],
64+
],
65+
]) ?>
66+
67+
68+
<?= Html::submitButton('Update', ['class' => 'btn btn-success']);?>
69+
<?php ActiveForm::end();?>

0 commit comments

Comments
 (0)