buttflattery / yii2-formwizard

A Yii2 plugin used for creating stepped form or form wizard using yii\widgets\ActiveForm and \yii\db\ActiveRecord
https://yii2plugins.omaraslam.com/formwizard
Other
96 stars 13 forks source link

Error tabularEvents #79

Open girishcp opened 4 years ago

girishcp commented 4 years ago

@buttflattery

My widget is working fine but when i am using select2 with the tabularEvents in the "STEP_TYPE_TABULAR" then getting the following error.

Setting unknown property: yii\bootstrap\ActiveField::tabularEvents

here its my code...


$step1 =[

'model' => $mymodel,

//set step type to tabular
'type' => FormWizard::STEP_TYPE_TABULAR,

'fieldConfig' => [      
    'content_support_title' => [
        'widget' => Select2::class,
        'containerOptions' => [
            'class' => 'form-group'
        ],
        'options' => [
            'data' => ArrayHelper::map(\backend\modules\smedb\models\domains::find()->limit(50)->all(), 'id', 'expertise', 'domain'),
            'options' => [
                'class' => 'form-control'
            ],
            'theme' => Select2::THEME_BOOTSTRAP,
            'pluginOptions' => [
                'allowClear' => true,
                'placeholder' => 'Select domain'
            ]
        ],

        //set tabular events for select2 fix which doesnot work correctly after cloning
        'tabularEvents' => [

            'beforeClone' => "function(event, params){
                //fix for select2 destroy the plugin

                let element = $(this);
                element.select2('destroy');
            }",
            "afterClone" => "function(event, params){
                //bind select2 again after clone

                let element = $(this);
                let elementId = $(this).attr('id');
                let dataKrajee = eval(element.data('krajee-select2'));
                let dataSelect2Options = element.data('s2-options');
                $.when(element.select2(dataKrajee)).done(initS2Loading(elementId, dataSelect2Options));
            }",
            "afterInsert" => "function(event,params){
                //initialize the options for the select2 after initializing

                let selectElement = $(this).find('.field-shoottag-'+params.rowIndex+'-tag_id > select');
                let dataKrajee = eval(selectElement.data('krajee-select2'));

                //update the dataset attribute to the
                if (typeof selectElement[0].dataset.select2Id !== 'undefined') {

                    //get the old dataset which has the old id of the input the select2 is bind to 
                    let oldDataSelect2Id = selectElement[0].dataset.select2Id;

                    //delete the old dataset
                    delete selectElement[0].dataset.select2Id;

                    //add the new dataselect pointing to the new id of the cloned element
                    let newDataSelect2Id = oldDataSelect2Id.replace(
                    /\-([\d]+)\-/,
                    '-' + parseInt(params.rowIndex) + '-'
                    );

                    //add the new dataset with the new cloned input id 
                    selectElement[0].dataset.select2Id= newDataSelect2Id;
                }
                selectElement.select2(dataKrajee);
            }"
        ]
    ]
]

];`
girishcp commented 4 years ago

@buttflattery did you get a chance to look into this issue.

buttflattery commented 4 years ago

@girishcp not yet, i am on vacations currently cant reach to my pc have you matched your code with the demos available here https://yii2plugins.omaraslam.com/formwizard/tabular-step you can see the select2 working , but if everything matches with the code there i would have to look into it again once i come back tomorrow evening

girishcp commented 4 years ago

Sorry to disturb you in your holiday. Please enjoy your vacation and take care of yourself.

On Sat, 12 Sep, 2020, 11:25 pm Coackroach, notifications@github.com wrote:

@girishcp https://github.com/girishcp not yet, i am on vacations currently cat reach to my pc have you matched your code with the demos available here https://yii2plugins.omaraslam.com/formwizard/tabular-step you can see the select2 working , but if everything matches with the code there i would have to look into it again once i come back tomorrow evening

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/buttflattery/yii2-formwizard/issues/79#issuecomment-691524277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFTC4ONCRQEZ6JU4JD6ZKCTSFOYYNANCNFSM4RHKTW3A .

buttflattery commented 4 years ago

@girishcp i will look into it as soon i come back , but i think this was due to a recent update to add missing default options support for the active field , just rty to switch your version in the composer.json to the the following

"buttflattery/yii2-formwizard": "dev-master#7b7942f5555d528cd46c5dbc55de71b076bcfca5",

and run

composer update

and then verify if it works ? i doubt that it will as i allowed to pass all options to the active field and i need to reset any custom option name like tabularEvents when passing on to the active field options, if you can add a fix for it that will be good otherwise you can switch to the above mentioned commit and continue without error , but you wont be able to set all options for the activeField that are added in the latest commit

girishcp commented 4 years ago

@buttflattery I have updated the formwizard as suggested but it also starts showing the tabs but having an issue with the add new in the tab. its not showing the select2 dropdown list as you can see in the below screenshot.

image

girishcp commented 4 years ago

@buttflattery I have updated with the old version "Release V1.6.17" and it start working.

buttflattery commented 4 years ago

@girishcp alrigth i will fix it up soon and will update you.

girishcp commented 4 years ago

@buttflattery Thank you so much.

buttflattery commented 4 years ago

@girishcp please pull the latest code by running composer update , should be working correctly now. If everything goes fine you can close the issue

girishcp commented 4 years ago

@buttflattery Thanks for working on this issue, the issue has been resolved now but found more issue on this widget after the update.

When I am adding one more items in the "STEP_TYPE_TABULAR" form then it's adding the 2 items in one go and when am trying to delete the blank item then it deleting the existing top one.

The delete (cross button) option also stops working.

The same issue with the SELECT2 field, its also stops working.

buttflattery commented 4 years ago

hmm strange i tested it though, can you share the exact code you are using? is it the same one above?

girishcp commented 4 years ago

@buttflattery yes, I am using the same code as above, this is a problem with all the versions. When we click on the add button to add one more item in our tab then its adding 2 items by default.

buttflattery commented 4 years ago

@girishcp alright i am looking into it and will push the fix soon

girishcp commented 3 years ago

@buttflattery It's been a long time didn't hear anything from you, I hope everything is fine at your end. Did you get time to fix the issue?

ZulfikriLbs commented 3 years ago

@girishcp , you have to change this code let selectElement = $(this).find('.field-shoottag-'+params.rowIndex+'-tag_id > select'); to let selectElement = $(this).find('.field-{your_model_class_name}-'+params.rowIndex+'-{your_field_name} > select');

hope this help.

girishcp commented 3 years ago

@ZulfikriLbs thanks for this update, do I need to update this code in the latest version of formwidget.

ZulfikriLbs commented 3 years ago

@girishcp maybe best to use the latest version of formwidget, but i think it's not necessary.

girishcp commented 3 years ago

@ZulfikriLbs Thank you, actually, I am asking these questions because I have raised several issues on this widget.

buttflattery commented 3 years ago

@girishcp sorry for the delays , i havent been able to give time to my personal projects due to the workload currently and still i am not free from the project. I will be getting free in the next week and will start fixing all the issues on the widget.