-3

hi all i'm a noob of yii and i'm trying to get the kartiks to work, but I can't get them to load the dependency.I'm trying to make the kartik work but I can't get it to load the dependency, if I see the calls that are made through yii's built-in debugging the scream that is present in the 'URL' parameter is not really computed, I've also tried to write it fixed but it's not really thought. If I do a simple echo, however, it comes back correct.

       <?=$form->field($model, 'name')->
                widget(Select2::classname(), ['data' => $listdataA,
                    'id' => 'invoice-name',
                    'options' => ['placeholder' => 'Seleziona anagrafica ...', 'id' => 'lvl-0',],
                    'pluginOptions' => [
                        'allowClear' => true
                    ],
                    'pluginEvents' => [
                        'select2:select' => new JsExpression("function (e)    {
                         var id=e.params.data.id;
                        $.get('index.php?r=invoice/get-location-address', {id: id}, function(data) {
                         if (data !== null) {
                        document.getElementById('piva').value=data.PIVA;
                       document.getElementById('indi').value=data.Indirizzo;
                        } else {
                            //if data wasn't found the alert.
                         alert('We\'re sorry but we couldn\'t load the the location data!');
                        }
                     });
                    }")]
        ]);
        ?>
        <?= $form->field($model, 'attn')->textInput(['maxlength' => true, 'placeholder' => 'ATTN', 'id' => 'piva'])->label(false) ?>
        <?= $form->field($model, 'address')->textarea(['rows' => 6, 'placeholder' => 'Address', 'id' => 'indi'])->label(false) ?>
        <?php
        echo $form->field($model, 'cd_contact')->widget(DepDrop::classname(), [
            'options' => ['placeholder' => 'Select ...'],
            'type' => DepDrop::TYPE_SELECT2,
            'select2Options' => ['pluginOptions' => ['allowClear' => true]],
            'pluginOptions' => [
                'depends' => [Html::getInputId($model, 'name')], //['lvl-0'],
                'url' => Url::to(['/contact/list']),
                'loadingText' => 'caricamento dati ...',
            ]
        ]);
        ?>

in the controller

     public function actionList() {

    Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
    $out = [];
    if (isset($_POST['depdrop_parents'])) {
        $id = end($_POST['depdrop_parents']);
        $list = Contact::find()->andWhere(['id_ana_ref' => $id])->asArray()->all();
        var_dump($list);
        $selected = null;
        if ($id != null && count($list) > 0) {
            $selected = '';
            foreach ($list as $i => $account) {
                $out[] = ['id' => $account['id_contact'], 'name' => $account['Name']];
                if ($i == 0) {
                    $selected = $account['id_contact'];
                }
            }
            // Shows how you can preselect a value
            return ['output' => $out, 'selected' => $selected];
        }
    }
  • Can you read again your question and improve it highlighting issues and needs? I would avoid the repetition of the not loaded dependencies. If clearer, written once is enough. And be more precise of what you really require. Thanks. – axel May 19 '20 at 06:00
  • Hi Axel, the problem was found in the select2:select if i run a java code in this event the drop stop to working – marco cardinale May 20 '20 at 06:53

1 Answers1

-2

solved if you put any java on kartick they avoid standard code

solution

 <?=
                $form->field($model, 'name')->
                widget(Select2::classname(), ['data' => $listdataA,
                    'id' => 'invoice-name',
                    'options' => ['placeholder' => 'Seleziona anagrafica ...' ,'id' => 'lvl-0',],
                    'pluginOptions' => [
                        'allowClear' => true
                    ],
                    ]);
       ?>
        <?= $form->field($model, 'attn')->textInput(['maxlength' => true, 'placeholder' => 'ATTN','onclick'=>'magsearch()', 'id' => 'piva'])->label(false) ?>
        <?= $form->field($model, 'address')->textarea(['rows' => 6, 'placeholder' => 'Address', 'id' => 'indi'])->label(false) ?>
        <?php
        // $url = \yii\helpers\Url::to(['index.php?r=contact/list']);
        echo $form->field($model, 'cd_contact')->widget(DepDrop::classname(), [
            'data' => $datac,
            'options' => ['placeholder' => 'carico ...'],
            'type' => DepDrop::TYPE_SELECT2,
            'select2Options' => ['pluginOptions' => ['allowClear' => true]],
            'pluginOptions' => [
                'depends' => ['lvl-0'],
                'url' => Url::to(['/contact/list']),
             //   'params' => ['lvl-0'],
                'loadingText' => 'caricamento dati ...',
            ]
        ]);
        ?>
  • 1
    Can you please explain the solution? What does mean: "if you put any java on kartick they avoid standard code" ? stackoverflow is used to write clear questions and clear answers. Put yourself in the shoes of a reader out of context, before to write. Also naming is important, you wrote kartick, kartiks, kartik. Typos are fine, but here there are too many. That's also the reason you got downvotes. – axel May 20 '20 at 08:36
  • Sorry but it's my first time on this portal, maybe I could suggest you to be a little kinder to those who are just new and do not put a less on all the answers that I give you, if all visitors to this portal are like you, I remain a moment perplexed. – marco cardinale May 21 '20 at 09:38
  • anyway the solution is this if you put any javascript in the "select2:select" option this overrides the standard function and consequently the element no longer works. – marco cardinale May 21 '20 at 09:40
  • I didn't insult you or meant to make you feel bad. I just mentioned you the things that you can improve and fix, both in your question and answer - like clarification, namings, indentation. You didn't fix them (you can always edit them) so I might also think that if all users don't follow tips or suggestions to improve their questions or answers, what can happen to Stackoverflow? – axel May 22 '20 at 12:19