From dc1c8c706833c12d2d75f5891d919f7fc214d79a Mon Sep 17 00:00:00 2001 From: SilverFire - Dima Naumenko Date: Fri, 13 Nov 2015 23:35:49 +0200 Subject: [PATCH] Added MultipleMailCombo; MailCombo - added activeWhen property --- src/widgets/combo/MailCombo.php | 8 +++--- src/widgets/combo/MultipleMailCombo.php | 36 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/widgets/combo/MultipleMailCombo.php diff --git a/src/widgets/combo/MailCombo.php b/src/widgets/combo/MailCombo.php index e724dbb9..4bd93491 100644 --- a/src/widgets/combo/MailCombo.php +++ b/src/widgets/combo/MailCombo.php @@ -23,6 +23,8 @@ class MailCombo extends Combo /** @inheritdoc */ public $_rename = ['text' => 'mail']; + public $activeWhen = ['server/server']; + /** @inheritdoc */ public function getFilter() { @@ -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)); } } \ No newline at end of file diff --git a/src/widgets/combo/MultipleMailCombo.php b/src/widgets/combo/MultipleMailCombo.php new file mode 100644 index 00000000..7bfba2a2 --- /dev/null +++ b/src/widgets/combo/MultipleMailCombo.php @@ -0,0 +1,36 @@ + [ + '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)); + } +} \ No newline at end of file