loveorigami / yii2-modal-ajax

A wrapper around Yii2 Bootstrap Modal for using an ActiveForm via AJAX inside.
MIT License
50 stars 30 forks source link

ajaxSubmit: not able to disable option #16

Closed Commifreak closed 5 years ago

Commifreak commented 5 years ago

... it is not possible to disable ajaxSubmit, because of: https://github.com/loveorigami/yii2-modal-ajax/blob/master/src/ModalAjax.php#L154

The generated JS contains:

ajaxSubmit: 
});

which leads to syntax error. PHP false for ajaxSubmit returns nothing when used there.

Corrected code would something like:

        $view->registerJs("
            jQuery('#$id').kbModalAjax({
                url: '$url',
                size:'sm',
                ajaxSubmit: ".($this->ajaxSubmit ? true : "false")."
            });
        ");

Could you re-test the ajaxSubmit option to verify if its working?

loveorigami commented 5 years ago

May be better

        $view->registerJs("
            jQuery('#$id').kbModalAjax({
                url: '$url',
                size:'sm',
                ajaxSubmit: '$this->ajaxSubmit'
            });
        ");

try and I fix it.

Commifreak commented 5 years ago

Hi,

Doesnt work either, I've found the core problem: https://github.com/loveorigami/yii2-modal-ajax/blob/master/src/assets/js/kb-modal-ajax.js#L39

options.ajaxSubmit || true is always true.

Examples:

false || true => true '' || true => true 'anystring' || true => 'anystring' BUT in https://github.com/loveorigami/yii2-modal-ajax/blob/master/src/assets/js/kb-modal-ajax.js#L66 it is true again, because it is a set string!

We need a fix in the js here: If NOT false it is true.

Commifreak commented 5 years ago

Working perfectly now.