surveyjs / survey-creator

Scalable open-source survey software to generate dynamic JSON-driven forms within your JavaScript application. The form builder features a drag-and-drop UI, CSS Theme Editor, and GUI for conditional logic and form branching.
https://surveyjs.io/open-source
Other
901 stars 372 forks source link

Allow to add sub items in toolbox similar to text and rating #5737

Closed andrewtelnov closed 2 months ago

andrewtelnov commented 2 months ago

Developers want to add the ability to add this functionality for different toolbox items, not only for text and rating. Here is the request in our Support Center. Currently it is hard coded.

OlgaLarina commented 2 months ago
novikov82 commented 2 months ago

@novikov82

novikov82 commented 2 months ago
    // create new group, move there old items
    creator.toolbox.addItem({ name: "matrices" }, 11);
    const matrices = creator.toolbox.getItemByName("matrices");
    const MatrixItem = creator.toolbox.getItemByName("matrix");
    const MatrixDropdownItem = creator.toolbox.getItemByName("matrixdropdown");
    const MatrixDynamicItem = creator.toolbox.getItemByName("matrixdynamic");
    matrices.addSubitem(MatrixItem);
    matrices.addSubitem(MatrixDropdownItem);
    matrices.addSubitem(MatrixDynamicItem);
    creator.toolbox.removeItem("matrix");
    creator.toolbox.removeItem("matrixdropdown");
    creator.toolbox.removeItem("matrixdynamic");

    // create new group, move there new items (the same type, different json)
    creator.toolbox.addItem({ name: "booleans", title: "Booleans" }, 6);
    const booleans = creator.toolbox.getItemByName("booleans");
    const BooleanItem = creator.toolbox.getItemByName("boolean");
    booleans.addSubitem(BooleanItem);
    booleans.addSubitem({ name: "boolradio", json: { type: "boolean", renderAs: "radio" }, title: "Radio" });
    booleans.addSubitem({ name: "boolcheckbox", json: { type: "boolean", renderAs: "checkbox" }, title: "Checkbox" });
    creator.toolbox.removeItem("boolean");

    // add new items (the same type, different json) to existing item
    const image = creator.toolbox.getItemByName("image");
    image.addSubitem({ name: "imagedefault", json: { type: "image" }, title: "Image" });
    image.addSubitem({ name: "imagevideo", json: { type: "image", contentMode: "video" }, title: "Video" });
    image.addSubitem({ name: "imageyoutube", json: { type: "image", contentMode: "youtube" }, title: "Youtube" });
novikov82 commented 2 months ago

But now we can support only subitems for item that corresponds to some question type:

    // create subitems from old items
    const MatrixItem = creator.toolbox.getItemByName("matrix");
    const MatrixDropdownItem = creator.toolbox.getItemByName("matrixdropdown");
    const MatrixDynamicItem = creator.toolbox.getItemByName("matrixdynamic");
    MatrixItem.title = "Matrix";
    MatrixItem.addSubitem({ name: "matrixdefault", json: { type: "matrix" }, title: "Single-Select" });
    MatrixItem.addSubitem(MatrixDropdownItem);
    MatrixItem.addSubitem(MatrixDynamicItem);
    creator.toolbox.removeItem("matrixdropdown");
    creator.toolbox.removeItem("matrixdynamic");

    // create subitems from new items (the same type, different json)
    const booleans = creator.toolbox.getItemByName("boolean");
    booleans.addSubitem({ name: "booleandefault", json: { type: "boolean" }, title: "Slider" });
    booleans.addSubitem({ name: "boolradio", json: { type: "boolean", renderAs: "radio" }, title: "Radio" });
    booleans.addSubitem({ name: "boolcheckbox", json: { type: "boolean", renderAs: "checkbox" }, title: "Checkbox" });

    // create subitems from new items (different types type, different json)
    const panels = creator.toolbox.getItemByName("panel");
    panels.addSubitem({ name: "paneldefault", json: { type: "panel" }, title: "Slider" });
    panels.addSubitem({ name: "paneldynamic", json: { type: "paneldynamic" }, title: "Dynamic Panel" });
    panels.addSubitem({ name: "paneltabs", json: { type: "paneldynamic", "renderMode": "tab" }, title: "Tabbed Panel" });
    creator.toolbox.removeItem(creator.toolbox.getItemByName("paneldynamic"));
JaneSjs commented 2 months ago

@novikov82 @OlgaLarina Please take note that sub-items should be also unavailable within the Add Question button's drop-down menu: image