Browse Source

修复select2边框不变色

wechat_public_accounts
blobt 5 years ago
parent
commit
6bdc883ab6
  1. 2
      common/models/Category.php
  2. 6
      kcadmin/views/category/_form.php
  3. 11
      kcadmin/web/css/site.css
  4. 3
      vendor/blobt/web/IcheckAsset.php
  5. 14
      vendor/blobt/widgets/Icheck.php
  6. 13
      vendor/blobt/widgets/Select2.php

2
common/models/Category.php

@ -39,7 +39,7 @@ class Category extends \yii\db\ActiveRecord {
*/ */
public function rules() { public function rules() {
return [ return [
[['cat_name'], 'required'],
[['icon_type','cat_name','created_at'], 'required'],
[['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], [['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'],
[['description'], 'string'], [['description'], 'string'],
[['cat_name', 'icon'], 'string', 'max' => 64], [['cat_name', 'icon'], 'string', 'max' => 64],

6
kcadmin/views/category/_form.php

@ -11,8 +11,6 @@ use blobt\widgets\Icheck;
/* @var $model common\models\Category */ /* @var $model common\models\Category */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<div class="box-body"> <div class="box-body">
@ -21,9 +19,9 @@ use blobt\widgets\Icheck;
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'icon_type')->widget(Select2::className(), ["data" => $model::$iconType]) ?>
<?= $form->field($model, 'icon_type')->widget(Select2::className(), ["items" => $model::$iconType]) ?>
<?= $form->field($model, 'icon_type')->widget(Icheck::className(), ["items" => ["a" => "A", "b" => "B"]]) ?>
<?php // $form->field($model, 'icon_type')->widget(Icheck::className(), ["items" => ["a" => "Option A", "b" => "Option B", "c" => "Option C"]]) ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?> <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>

11
kcadmin/web/css/site.css

@ -31,3 +31,14 @@
.login-form h6 { .login-form h6 {
text-align: center; text-align: center;
} }
/*修复select2插件 from表框颜色不生效*/
.form-group.has-error .select2-selection, .form-group.has-error .select2-selection {
border-color: #dd4b39;
box-shadow: none;
}
.form-group.has-success .select2-selection, .form-group.has-success .select2-selection {
border-color: #00a65a;
box-shadow: none;
}

3
vendor/blobt/web/IcheckAsset.php

@ -44,5 +44,8 @@ class IcheckAsset extends AssetBundle {
public $js = [ public $js = [
'icheck.min.js' 'icheck.min.js'
]; ];
public $depends = [
'yii\web\JqueryAsset'
];
} }

14
vendor/blobt/widgets/Icheck.php

@ -66,9 +66,6 @@ class Icheck extends InputWidget {
if ($this->hasModel() && !isset($options['name'])) { if ($this->hasModel() && !isset($options['name'])) {
$this->name = $this->options['name'] = Html::getInputName($this->model, $this->attribute); $this->name = $this->options['name'] = Html::getInputName($this->model, $this->attribute);
} }
if (count($this->items) > 1) {
$this->name .="[]";
}
} }
/** /**
@ -84,7 +81,10 @@ class Icheck extends InputWidget {
*/ */
protected function registerJs() { protected function registerJs() {
$js = <<<SCRIPT $js = <<<SCRIPT
$("input[name='{$this->name}']").iCheck();
$("input[name='{$this->name}']").iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue',
});
SCRIPT; SCRIPT;
$this->getView()->registerJs($js); $this->getView()->registerJs($js);
} }
@ -92,9 +92,11 @@ SCRIPT;
protected function renderCheckBox() { protected function renderCheckBox() {
$line = []; $line = [];
foreach ($this->items as $key => $val) { foreach ($this->items as $key => $val) {
$line[] = Html::tag('input', $key, ["type" => "radio", "name" => $this->name]);
$input = Html::tag('input', $key, ["type" => "radio", "name" => $this->name]);
$line[] = Html::tag('label', $input ." ". $val);
} }
return implode("\n", $line);
$content = implode("\n", $line);
return Html::tag('div', $content);
} }
} }

13
vendor/blobt/widgets/Select2.php

@ -45,13 +45,18 @@ class Select2 extends InputWidget {
/** /**
* @var array select的选项 * @var array select的选项
*/ */
public $data = [];
public $items = [];
/** /**
* @var array select 的html选择 * @var array select 的html选择
*/ */
public $options; public $options;
/**
* @var string 默认显示的提示
*/
public $promptText = '请选择';
/** /**
* @inheritdoc * @inheritdoc
* @throws \ReflectionException * @throws \ReflectionException
@ -71,6 +76,10 @@ class Select2 extends InputWidget {
if ($this->hasModel() && !isset($options['name'])) { if ($this->hasModel() && !isset($options['name'])) {
$this->name = $this->options['name'] = Html::getInputName($this->model, $this->attribute); $this->name = $this->options['name'] = Html::getInputName($this->model, $this->attribute);
} }
if (!empty($this->promptText)) {
$this->options = ArrayHelper::merge($this->options, ['prompt' => $this->promptText]);
}
} }
/** /**
@ -100,7 +109,7 @@ SCRIPT;
if ($this->hasModel()) { if ($this->hasModel()) {
$value = ArrayHelper::getValue($this->model, $this->attribute); $value = ArrayHelper::getValue($this->model, $this->attribute);
} }
return Html::dropDownList($this->name, $value, $this->data, $this->options);
return Html::dropDownList($this->name, $value, $this->items, $this->options);
} }
} }
Loading…
Cancel
Save