survey-creator icon indicating copy to clipboard operation
survey-creator copied to clipboard

Special choices should not be visible if we prevent adding new items in onCollectionItemsAllowOperations function

Open JaneSjs opened this issue 3 years ago • 4 comments

Update The following code could be used to achieve it:

import { settings } from "survey-core";
settings.showDefaultItemsInCreatorV2 = false;

The new creator.onCollectionItemsAllowOperations -> options.allowAdd option (https://github.com/surveyjs/survey-creator/issues/3923) allows to prevent users from adding new items. However, if the question disables the None and Other options, these options should not be visible when we prevent users from adding new choices.

creator.onCollectionItemAllowOperations.add((function(sender, options){
        if(options.propertyName === 'choices'){
            options.allowDelete = false;
            options.allowEdit = false;
            options.allowAdd = false;    
        }
}));

 creator.JSON = {
        elements: [
            {
                type: "radiogroup",
                name: "question1",
                showOtherItem: false,
                showNoneItem: false,
                choices: [
                    { value: 0, text: "Item 1" },
                    { value: 1, text: "Item 2" },
                    { value: 2, text: "Item 3" },
                    { value: 3, text: "Item 4" },
                    { value: 4, text: "Item 5" }
                ]
            },
            {
                type: "radiogroup",
                name: "question2",
                showOtherItem: false,
                showNoneItem: false,
                choices: [
                    { value: 0, text: "Option 1" },
                    { value: 1, text: "Option 2" },
                    { value: 2, text: "Option 3" }
                ]
            }
        ]
    };

https://plnkr.co/edit/nOXqE8b8Yfw6W20f

image

JaneSjs avatar Apr 05 '23 13:04 JaneSjs

Special choices could be hidden in this event:

    creator.onSurveyInstanceCreated.add(function(sender, options) {
        //If we are creating a surface for designer surface
        if(options.reason == "designer") {
            options.survey.onShowingChoiceItem .add(function (sender, options){
                if(options.question.choices.indexOf(options.item) == -1) {
                    options.visible = false;
                }
            });
        }
    });

https://plnkr.co/edit/AXeOUo6ffmnqHj2T

novikov82 avatar Apr 17 '23 09:04 novikov82

T20331 - Disable removing of choices and choice suggestions https://surveyjs.answerdesk.io/internal/ticket/details/T20331


The following issues exist: View Demo The allowDelete, allowEdit, and allowAdd options are disabled.

 creator.onCollectionItemAllowOperations.add((function(sender, options){
            if(options.propertyName === 'choices'){
                options.allowDelete = false;
                options.allowEdit = false;
                options.allowAdd = false;    
            }
}));

Still, it is possible to add, remove, or edit choices via a property grid and the batch editor. image

image image

P.S. Let's wait till a user's scenario clarification.

JaneSjs avatar Oct 18 '24 17:10 JaneSjs

The creator.onGetPropertyReadOnly disables choice editing: View Plunker. image

However, those special (Other, None, Select All) options are still rendered though they do not actually exist. image

To hide these choices, handle the following function: View Demo.

 creator.onSurveyInstanceCreated.add(function(sender, options) {            
        if(options.area == "designer-tab") {
            options.survey.onShowingChoiceItem.add(function (sender, options){
                if(options.question.choices.indexOf(options.item) == -1) {
                    options.visible = false;
                }
            });
        }
});
creator.JSON = {};

JaneSjs avatar Oct 21 '24 06:10 JaneSjs

I'm reopening this issue again to discuss.

The problem with the following setting is that it disables special/default items for all questions.

import { settings } from "survey-core";
settings.showDefaultItemsInCreatorV2 = false;

Perhaps, we should actually consider hiding special choices when a question's editing is disabled via the following code: View Demo.

creator.onElementAllowOperations.add((sender, options) => {
   options.allowEdit = false; // Disable element editing
});

image

The issue was recently reported at T21107 - None and other itemvalue does not get disabled style.

JaneSjs avatar Dec 16 '24 09:12 JaneSjs