Yii Framework Forum: SELECT2 Box faulty - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SELECT2 Box faulty [canceled]

#1 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 305
  • Joined: 20-April 17
  • Location:Hannover

Posted 11 January 2018 - 09:21 PM

In order to prevent getting all values of database in DropDownBox I code like this in model:

    public static function get_ArrayOfMailAdresses() {
        $x = 0;
        $returnValue = array();
   	$valid_sem = '/;/';
   	$auswahl = Mailausgang::find(['id' => 'value'])->orderBy(['id' => SORT_ASC])->asArray()->all();
        foreach ($auswahl as $value) {
            if (!preg_match($valid_sem, $value['mail_antwortadresse'])) {
                $returnValue[$x] = $value['mail_antwortadresse'];
                //return yii\helpers\ArrayHelper::map($auswahl, 'mail_antwortadresse', 'mail_antwortadresse');
            }
            $x++;
        }
        return $returnValue;
    }

In my GridView, I'll get all records withou semicolon in DropDownBox, as it's intended.
If I select one, I will get no hit. Any ideas, where is bug?

        
                'attribute' => 'mail_antwortadresse',
           	'label' => Yii::t('app', 'Zieladresse'),
           	'contentOptions' => [
                    'style' => ['width' => '150px;']
           	],
                'value' => function($model) {
                    if ($model->mail_antwortadresse) {
                   	return $model->mail_antwortadresse;
                    } else {
                   	return NULL;
                    }
           	},
           	'filterType' => GridView::FILTER_SELECT2,
           	'filter' => Mailausgang::get_ArrayOfMailAdresses(),
                'filterWidgetOptions' => [
               	'pluginOptions' => ['allowClear' => true],
           	],
           	'filterInputOptions' => ['placeholder' => 'Mailadresse', 'id' => 'grid-zieladresse']
            ],

0

#2 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 305
  • Joined: 20-April 17
  • Location:Hannover

Posted 11 January 2018 - 09:35 PM

Unless I don't have any plausible explanation, i solved problem coding like this

    public static function get_ArrayOfMailAdresses() {
        $auswahl = Mailausgang::find(['id' => 'value'])->orderBy(['id' => SORT_ASC])->where(['not like', 'mail_antwortadresse', '%;%', false])->asArray()->all();
        return yii\helpers\ArrayHelper::map($auswahl, 'mail_antwortadresse', 'mail_antwortadresse');
   }

I yet am interested knowing, why my first solution doesn't work...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users