Enhance README with security note on postMessage and add allowBack option for item navigation

This commit is contained in:
HoshinoKoji 2025-03-07 16:36:30 +08:00
parent 6ea2608860
commit 3f97ec078c
3 changed files with 10 additions and 3 deletions

View File

@ -22,6 +22,8 @@ window.postMessage({
}, '*'); }, '*');
``` ```
**Security Note:** When using postMessage in production, always specify an exact target origin instead of '*' to prevent potential cross-site scripting vulnerabilities. The component uses the `settings.origin` property for sending responses back to ensure proper security.
## Input Schema ## Input Schema
### Root Object ### Root Object
@ -47,7 +49,8 @@ Each item in the `items` array represents a question with the following structur
optValues: ['value1', 'value2'], // For 'radio', 'checkbox', 'scale' optValues: ['value1', 'value2'], // For 'radio', 'checkbox', 'scale'
required: true, // Whether answer is required required: true, // Whether answer is required
minOpts: 1, // For 'checkbox', minimum options to select minOpts: 1, // For 'checkbox', minimum options to select
maxOpts: 3 // For 'checkbox', maximum options to select maxOpts: 3, // For 'checkbox', maximum options to select
allowBack: true // Override global back button setting for this item
} }
``` ```
@ -64,6 +67,7 @@ Each item in the `items` array represents a question with the following structur
| required | boolean | No | Whether an answer is required (default: false) | | required | boolean | No | Whether an answer is required (default: false) |
| minOpts | number | No | Minimum options to select for 'checkbox' (default: 1) | | minOpts | number | No | Minimum options to select for 'checkbox' (default: 1) |
| maxOpts | number | No | Maximum options to select for 'checkbox' (default: total options) | | maxOpts | number | No | Maximum options to select for 'checkbox' (default: total options) |
| allowBack | boolean | No | Override global back button setting for this specific item, useful for splitting the survey into sections |
### Settings Object ### Settings Object

View File

@ -11,7 +11,8 @@
"type": "text", "type": "text",
"title": "Text", "title": "Text",
"required": true, "required": true,
"desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." "desc": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"allowBack": false
}, },
{ {
"type": "text", "type": "text",

View File

@ -77,7 +77,9 @@ export default {
}, },
methods: { methods: {
updateBackButton() { updateBackButton() {
this.uiStatus.backButtonDisabled = !this.settings.allowBack || (this.currentIdx === 0); const itemAllowBack = this.items[this.currentIdx].allowBack === undefined ?
this.settings.allowBack : this.items[this.currentIdx].allowBack;
this.uiStatus.backButtonDisabled = !itemAllowBack || (this.currentIdx === 0);
}, },
updateNextButton() { updateNextButton() {
if (this.currentIdx === this.items.length - 1) { if (this.currentIdx === this.items.length - 1) {