Skip to content

Commit

Permalink
Added MultipleMailCombo; MailCombo - added activeWhen property
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 13, 2015
1 parent c15ffeb commit dc1c8c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/widgets/combo/MailCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MailCombo extends Combo
/** @inheritdoc */
public $_rename = ['text' => 'mail'];

public $activeWhen = ['server/server'];

/** @inheritdoc */
public function getFilter()
{
Expand All @@ -36,13 +38,13 @@ public function getFilter()
/** @inheritdoc */
public function getPluginOptions($options = [])
{
return parent::getPluginOptions([
'activeWhen' => ['server/server'],
return parent::getPluginOptions(ArrayHelper::merge([
'activeWhen' => $this->activeWhen,
'select2Options' => [
'formatResult' => new JsExpression("function (data) {
return data.text;
}")
]
]);
], $options));
}
}
36 changes: 36 additions & 0 deletions src/widgets/combo/MultipleMailCombo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace hipanel\modules\hosting\widgets\combo;

use hiqdev\combo\Combo;
use yii\helpers\ArrayHelper;
use yii\web\JsExpression;

class MultipleMailCombo extends MailCombo
{
/** @inheritdoc */
public function getPluginOptions($options = [])
{
return parent::getPluginOptions(ArrayHelper::merge([
'select2Options' => [
'multiple' => true,
'tokenSeparators' => [', ', ' '],
'tags' => true,
'createSearchChoice' => new JsExpression(/** @lang JavaScript */'
function (term, data) {
if ($(data).filter(function () {
return this.text.localeCompare(term) === 0;
}).length === 0) {
if (term.match(/^[0-9a-zA-Z\._+-]+@([0-9a-z][0-9a-z_-]*\.)+[0-9a-z][0-9a-z-]*$/i)) {
return {
id: term,
text: term
};
}
}
}
')
]
], $options));
}
}

0 comments on commit dc1c8c7

Please sign in to comment.