---
title: Page Break and Page Merge
product: Survey Creator
description: Learn how to implement and use the page break and page merge features in Survey Creator to efficiently structure multi-page surveys. This JavaScript demo shows how survey authors can split a page into two or merge consecutive pages with just a few clicks.
framework: Vue 3
source: https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/vue3js
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Page Break and Page Merge (Vue 3)

Page breaks and page merge features help survey authors manage the survey structure more quickly and efficiently. Use a page break to split a single survey page into two: simply drag the Page Break item from the Toolbox and drop it between two elements on the design surface. Conversely, the page merge option lets you combine two consecutive pages into one. To merge, select Page 2 or any subsequent page on the design surface and click the "Merge with previous page" button at the top of that page. The elements from the selected page will be appended to the previous one.

To implement the page breaks and page merge functionalities to Survey Creator, follow the steps below:

1. Create a custom `PageBreak` class.           
Extend the `Question` class and override the `getType()` method.

2. Register icons for the Page Break toolbox item and Page Merge action button.         
Define SVG icons as string values and use the `SvgRegistry.registerIcon(name, svg)` method to register them.

3. Handle the [`onDragDropAllow`](/survey-creator/documentation/api-reference/survey-creator#onDragDropAllow) and [`onQuestionAdded`](/survey-creator/documentation/api-reference/survey-creator#onQuestionAdded) events.           
These events allow you to manage acceptable drop positions and split a page when users drag the Page Break item from the Toolbox onto the design surface.

4. Add the Page Break toolbox item.         
Pass an [`IQuestionToolboxItem`](/survey-creator/documentation/api-reference/iquestiontoolboxitem) object to the Toolbox's [`addItem`](/survey-creator/documentation/api-reference/questiontoolbox#addItem) method. Within this object, define the item's name and title, assign one of the icons registered on step 2, and specify a JSON object that this item produces.

5. Add the Page Merge action button.        
Handle the [`onElementGetActions`](/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event using a function. Within it, create and configure an [`IAction`](/form-library/documentation/api-reference/iaction) object by specifying its ID, title, icon, visibility rules, and a function to execute when users click this button. Add the `IAction` object to the `options.actions` array.

Refer to the Code tab to view the full code listing.

## Files

### `public/index.html`

```html
<div id="app" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0;"></div>
```

### `src/icons.js`

```js
export const pageBreakToolboxIcon = `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M20.75 16V19C20.75 20.52 19.52 21.75 18 21.75H6C4.48 21.75 3.25 20.52 3.25 19V16C3.25 15.59 3.59 15.25 4 15.25C4.41 15.25 4.75 15.59 4.75 16V19C4.75 19.69 5.31 20.25 6 20.25H18C18.69 20.25 19.25 19.69 19.25 19V16C19.25 15.59 19.59 15.25 20 15.25C20.41 15.25 20.75 15.59 20.75 16ZM18 2.25H6C4.48 2.25 3.25 3.48 3.25 5V8C3.25 8.41 3.59 8.75 4 8.75C4.41 8.75 4.75 8.41 4.75 8V5C4.75 4.31 5.31 3.75 6 3.75H18C18.69 3.75 19.25 4.31 19.25 5V8C19.25 8.41 19.59 8.75 20 8.75C20.41 8.75 20.75 8.41 20.75 8V5C20.75 3.48 19.52 2.25 18 2.25ZM4 12.75H5C5.41 12.75 5.75 12.41 5.75 12C5.75 11.59 5.41 11.25 5 11.25H4C3.59 11.25 3.25 11.59 3.25 12C3.25 12.41 3.59 12.75 4 12.75ZM20 11.25H19C18.59 11.25 18.25 11.59 18.25 12C18.25 12.41 18.59 12.75 19 12.75H20C20.41 12.75 20.75 12.41 20.75 12C20.75 11.59 20.41 11.25 20 11.25ZM10 12.75C10.41 12.75 10.75 12.41 10.75 12C10.75 11.59 10.41 11.25 10 11.25H9C8.59 11.25 8.25 11.59 8.25 12C8.25 12.41 8.59 12.75 9 12.75H10ZM15 12.75C15.41 12.75 15.75 12.41 15.75 12C15.75 11.59 15.41 11.25 15 11.25H14C13.59 11.25 13.25 11.59 13.25 12C13.25 12.41 13.59 12.75 14 12.75H15Z" /></svg>`;

export const pageMergeActionIcon = `<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M8.5 5.75V7H9.75C10.16 7 10.5 7.34 10.5 7.75C10.5 8.16 10.16 8.5 9.75 8.5H8.5V9.75C8.5 10.16 8.16 10.5 7.75 10.5C7.34 10.5 7 10.16 7 9.75V8.5H5.75C5.34 8.5 5 8.16 5 7.75C5 7.34 5.34 7 5.75 7H7V5.75C7 5.34 7.34 5 7.75 5C8.16 5 8.5 5.34 8.5 5.75ZM12.75 1H2.75C1.79 1 1 1.79 1 2.75V5.75C1 6.16 1.34 6.5 1.75 6.5C2.16 6.5 2.5 6.16 2.5 5.75V2.75C2.5 2.61 2.61 2.5 2.75 2.5H12.75C12.89 2.5 13 2.61 13 2.75V5.75C13 6.16 13.34 6.5 13.75 6.5C14.16 6.5 14.5 6.16 14.5 5.75V2.75C14.5 1.79 13.71 1 12.75 1ZM13.75 9C13.34 9 13 9.34 13 9.75V12.75C13 12.89 12.89 13 12.75 13H2.75C2.61 13 2.5 12.89 2.5 12.75V9.75C2.5 9.34 2.16 9 1.75 9C1.34 9 1 9.34 1 9.75V12.75C1 13.71 1.79 14.5 2.75 14.5H12.75C13.71 14.5 14.5 13.71 14.5 12.75V9.75C14.5 9.34 14.16 9 13.75 9Z" /></svg>`;
```

### `src/survey-json.js`

```js
export const surveyJson = {
  "pages": [{
    "name": "page1",
    "elements": [{
      "type": "text",
      "name": "question1"
    }, {
      "type": "text",
      "name": "question2"
    }]
  }, {
    "name": "page2",
    "elements": [{
      "type": "text",
      "name": "question3"
    }]
  }]
}
```

### `src/App.vue`

```html
<template>
    <SurveyCreatorComponent :model="creator" />
</template>
<script setup lang="ts">
    import { SurveyCreatorModel } from "survey-creator-core";
    import { SurveyCreatorComponent } from "survey-creator-vue";
    import { Question, Serializer, Action, ComputedUpdater, SvgRegistry } from "survey-core";
    import { pageBreakToolboxIcon, pageMergeActionIcon } from "./icons";
    import { surveyJson } from "./survey-json";
    import { SurveyHelper } from "survey-creator-core";
    import "survey-core/survey.i18n";
    import "survey-creator-core/survey-creator-core.i18n";
    import "survey-core/survey-core.css";
    import "survey-creator-core/survey-creator-core.css";
    import "./index.css";
    import SurveyTheme from "survey-core/themes";
    import { registerCreatorTheme } from "survey-creator-core";

    registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

    const PageBreakType = "pagebreak";
    
    class PageBreak extends Question {
        getType() {
            return PageBreakType;
        }
    }
    
    Serializer.addClass(PageBreakType, [], () => new PageBreak(""), "question");
    SvgRegistry.registerIcon("icon-toolbox-pagebreak", pageBreakToolboxIcon);
    SvgRegistry.registerIcon("icon-action-pagemerge", pageMergeActionIcon);
    
    function isPageBreak(el) {
        return el ? el.getType() === PageBreakType : false;
    }
    
    function moveElementsToPage(page, elements) {
        elements.forEach((el) => {
            el.parent.removeElement(el);
            page.addElement(el);
        });
    }
    const creator = new SurveyCreatorModel();
    // Do not allow placing a page break within a panel and at the beginning or end of a page
    creator.onDragDropAllow.add((_, options) => {
        const q = options.draggedElement;
        if (isPageBreak(q)) {
            const el = options.toElement;
            options.allow = !!el && !el.isPanel && (!el.parent || el.parent.isPage);
            if (el.isPage && el.elements.length < 2) {
                options.allow = false;
            }
            if (options.allow && el.page) {
                const page = el.page;
                const elements = page.elements;
                if (
                    options.insertBefore &&
                    elements.indexOf(options.insertBefore) === 0
                ) {
                    options.allow = false;
                }
                if (
                    options.insertAfter &&
                    elements.indexOf(options.insertAfter) === elements.length - 1
                ) {
                    options.allow = false;
                }
            }
        }
    });
    
    // Create a new page and move questions to it if the added element is a page break 
    creator.onQuestionAdded.add((_, options) => {
        const q = options.question;
        if (isPageBreak(q)) {
            const curPage = q.page;
            const index = curPage.indexOf(q);
            q.delete();
            const elements = [];
            for (let i = index; i < curPage.elements.length; i++) {
                elements.push(curPage.elements[i]);
            }
            const survey = creator.survey;
            const newPageName = SurveyHelper.getNewPageName(survey.pages);
            const newPageIndex = survey.pages.indexOf(curPage) + 1;
            const newPage = survey.addNewPage(newPageName, newPageIndex);
            moveElementsToPage(newPage, elements);
            creator.selectElement(newPage);
        }
    });
    
    // Add a page action that merges a page with the previous one
    creator.onElementGetActions.add((_, options) => {
        const page = options.element;
        if (page.isPage) {
            const action = new Action({
                id: "page_merge",
                visible: new ComputedUpdater(() => page.visibleIndex > 0),
                title: "Merge with previous page",
                iconName: "icon-action-pagemerge",
                iconSize: 16,
                action: () => {
                    const pages = creator.survey.pages;
                    const index = pages.indexOf(page);
                    if (index >= 1) {
                        creator.startUndoRedoTransaction("merge page");
                        moveElementsToPage(
                            pages[index - 1],
                            [].concat(page.elements)
                        );
                        page.delete();
                        creator.stopUndoRedoTransaction();
                    }
                }
            });
            options.actions.push(action);
        }
    });
    
    // Add a Page Break toolbox item
    creator.toolbox.addItem({
        name: "page_break",
        title: "Page Break",
        iconName: "icon-toolbox-pagebreak",
        showInToolboxOnly: true,
        json: { type: PageBreakType }
    }, 0);
    
    creator.toolbox.forceCompact = false;
    creator.showSurveyHeader = false;
    creator.JSON = surveyJson;
</script>
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/main.ts`

```ts
import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App);
app.mount("#app");
```

### `src/shims-vue.d.ts`

```ts
/* eslint-disable */
declare module "*.vue" {
    import type { DefineComponent } from "vue"
    const component: DefineComponent<{}, {}, any>
    export default component
}
```

### `.eslintrc.js`

```js
module.exports = {
    root: true,
    env: {
        node: true
    },
    extends: [
        "plugin:vue/vue3-essential",
        "eslint:recommended",
        "@vue/typescript/recommended",
        "@vue/prettier",
        "@vue/prettier/@typescript-eslint"
    ],
    parserOptions: {
        ecmaVersion: 2020
    },
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off"
    },
    overrides: [
        {
            files: [
                "**/__tests__/*.{j,t}s?(x)",
                "**/tests/unit/**/*.spec.{j,t}s?(x)"
            ],
            env: {
                jest: true
            }
        }
    ]
};
```

### `babel.config.js`

```js
module.exports = {
  presets: ["@vue/cli-plugin-babel/preset"]
};
```

### `package.json`

```json
{
  "name": "surveyjs-library-vue3",
  "version": "0.1.0",
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "tslib": "2.6.1",
    "vue": "^3.4.1",
    "survey-core": "latest",
    "survey-vue3-ui": "latest",
    "survey-creator-core": "latest",
    "survey-creator-vue": "latest",
    "vue-router": "^4.0.0-0",
    "vuex": "^4.0.0-0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.33.0",
    "@typescript-eslint/parser": "^2.33.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-pwa": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^5.0.2",
    "@vue/test-utils": "^2.0.0-0",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^7.0.0-0",
    "node-sass": "^4.12.0",
    "prettier": "^1.19.1",
    "sass-loader": "^8.0.2",
    "typescript": "~3.9.3"
  }
}
```

### `tsconfig.json`

```json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "jest"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/angular.md)
- [React](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/reactjs.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/vanillajs.md)
