leandrogehlen / yii2-querybuilder

Extension for Yii2 Framework to work with jQuery QueryBuilder
43 stars 34 forks source link

Question: is there a reason that rules isn't passed directly by pluginOptions? #18

Closed Bhoft closed 5 years ago

Bhoft commented 5 years ago

Hi i have seen your extension for the JQueryBuilder and have one Question.

Is there a reason that you pass the $rules to the QueryBuilderForm and not add it to the pluginOptions directly?

<?php QueryBuilderForm::begin([
    'rules' => $rules,
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            'filters' => [
                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
            ]
        ]
    ]
])?>

Which would then add JS code to set the rules.

instead of set it directly?

<?php QueryBuilderForm::begin([
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            'rules' => $rules,
            'filters' => [
                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
            ]
        ]
    ]
])?>

I mean you even didn't use the $rules given to the QueryBuilderForm e.g. add the json version already to the echo Html::hiddenInput($this->rulesParam); as value?

leandrogehlen commented 5 years ago

You can use the options property using the code above


<?php QueryBuilderForm::begin([
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            'rules' => new \yii\web\JsExpression($rules),
            'filters' => [
                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
            ]
        ]
    ]
])?>