Suggestion T3875
Visible to All Users

Confirmation on delete rule

created 5 years ago

Hi team,

I want to show my confirmation dialog on delete logic rule.

Please help me to know if this is supporting in surveyjs as of now.

Clipboard-File-1.png

Thanks,
Nitin

Answers approved by surveyjs Support

created 5 years ago

Hello,

You needn't to remove item yourself. You just need to set the options.allowRemove flag in the handler. I mentioned it in the original answer.

JavaScript
survey.logic.onLogicItemRemoving.add((_, options) => { // Show dialog here and set corresponding flag // Since the dialog is modal the show operation is synchronous options.allowRemove = false; // if removal is not allowed, true if item should be removed });

Thanks, Serge
SurveyJS Team

    Comments (2)

      Serge actually the problem is after removing rule manually, causing to trigger onLogicItemRemoving again and my attached function to this event will execute again so to avoid re execution I had to take a flag which is stoping to re open confirmation dialog but I want something to avoid re execution of onLogicItemRemoving so that this kind of hacking code will not require.

        Hello,

        The onLogicItemRemoving event is called then use pressed the "remove" button. You needn't to remove logic item by your self, it will be done by SurveyJS code if you set options.allowRemove = true; (that is the default value). Thus you needn't do anything except asking an end-user does he really want to delete this item. If no, set options.allowRemove to false and nothing more.

        Thanks, Serge
        SurveyJS Team

        created 5 years ago

        Hello,

        I've introduced the onLogicItemRemoving/onLogicItemRemoved events via the https://github.com/surveyjs/survey-creator/commit/1b2692f919953664a8fd9eae8a61909124f7bda2 commit.

        You can subscribe the onLogicItemRemoving event, ask confirmation and set the allowRemove flag to false to prevent deleting:

        JavaScript
        survey.logic.onLogicItemRemoving.add((_, options) => { options.allowRemove = false; });

        The events will be available in the nearest update.

        Thanks, Serge
        SurveyJS Team

          Comments (1)

            Hi Serge,

            Regarding confirmation dialog implementation on logic delete

            Implementation of this does not seems straight forward, and to achieve this I have to take another variable to take care that not to open confirmation dialog again on second call.

            Because removeItem function is calling two times-
            1- when user click on delete button to remove logic rule and
            2- when confirm dialog promise got resolved and we call again removeItem with allowRemove=true

            and removeItem will trigger onLogicItemRemoving event on every call.

            instead of this below hack can we make this code more appropriate. otherwise I have to go with approach only.

            Code I'm using
            isConfirmDialogActive=false;
            this.logic.onLogicItemRemoving.add(this.confirmOnLogicItemRemove.bind(this));

            private confirmOnLogicItemRemove(sender: SurveyLogic, options: any){
            if(!this.isConfirmDialogActive){
            options.allowRemove = false;
            ConfirmationDialog.Instance.show(this.getLocString("logic.delete.dialog.title"), this.getLocString("logic.delete.dialog.message"),
            this.getLocString("logic.delete.dialog.okButton"), this.getLocString("logic.delete.dialog.cancelButton")
            ).then(()=>{
            this.isConfirmDialogActive = true;
            this.logic.removeItem(options.item);
            },
            ()=>{
            this.isConfirmDialogActive = false;
            });
            } else {
            this.isConfirmDialogActive = false;
            }
            }