Kartik: DepDrop in Tabular Form

Hi guys,

I want to use DepDrop within TabularForms:

https://github.com/kartik-v/yii2-widget-depdrop/issues/83

Does anyone have a workaround? This extension is really great and it would be a huge feature in my app, but I can’t fix the Problem :tired_face:

Thank’s in advance!
Best regards,
Tobi

hmm, nobody an idea?

Can just anyone help who I have the extension to modify that I can use an inner function in an array like this

'pluginOptions' => [
                'depends' => function($model, $key, $index, $widget) { return ['tbl_company_id' . $model['id']]; }, 

Thank you!

okay, next step must be to modify the DepDrop.php.

How I have to set the closure incl. parameters? I have no experince with anonym. functions, can anyone give me a hint?

if(!is_array($this->pluginOptions['depends']))
    {
        $this->pluginOptions['depends'] = function ($model, $key) {  }; 
    }

closure in tabular form works so far:

'pluginOptions' => [
                'depends' => function($model) { var_dump($model); exit;},//return ['tbl_company_id-id_' . $model['id']]; },
                'initialize' => true,
                'url' => Url::to(['/person/depdrop']),
                'loadingText' => 'Loading Persons...',
            ]

DepDrop.php has been changed as following:

 public function run()
{   
                    
    if (empty($this->pluginOptions['url'])) {
        throw new InvalidConfigException("The 'pluginOptions[\"url\"]' property has not been set.");
    }
    if (empty($this->pluginOptions['depends'])) {
        throw new InvalidConfigException("The 'pluginOptions[\"depends\"]' property must be set."); // and must be an array of dependent dropdown element identifiers.");
    }
    
    // ========================
    // INSERT FOR TABULAR FORM
   // ========================

    if(!is_array($this->pluginOptions['depends']))
    {
        $this->pluginOptions['depends']($this->model); 
    }    
           
    
    
    if (empty($this->options['class'])) {
        $this->options['class'] = 'form-control';
    }
    if ($this->type === self::TYPE_SELECT2) {
        Config::checkDependency('select2\Select2', 'yii2-widget-select2', 'for dependent dropdown for Select2');
    }
    if ($this->type !== self::TYPE_SELECT2 && !empty($this->options['placeholder'])) {
        $this->data = ['' => $this->options['placeholder']] + $this->data;
    }
    $this->registerAssets();
}

but the result reflects NULL.

How can I access or fill the model object? I though the parent widget class a resoponsible for?