How to Execute JavaScript Function on Button Click in VueForm Builder Custom Element? #47
-
In the VueForm Builder configuration file (builder.config.js), I'm defining a custom element called "Alert button" (alertbutton). This button is intended to trigger an alert message when clicked. However, I'm unsure how to include the JavaScript function or code snippet that should execute upon clicking the button. Here's a snippet of the current configuration: // builder.config.js
export default {
element: {
types: {
alertbutton: {
label: 'Alert button',
category: 'static',
rules: [],
schema: {
buttonLabel: 'Alert',
type: 'button',
// Here I want to include a function or code snippet that executes when the button is clicked like alert("Test")
},
sections: {
// ...
},
separators: {
// ...
},
operators: [
// ...
],
}
}
}
} Could you please provide guidance on how to include a JavaScript function or code snippet that executes when the button is clicked within the VueForm Builder custom element configuration? Thank you for your assistance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Here's an example how you can subscribe to element events when using schema: So the syntax is: // builder.config.js
export default {
element: {
types: {
alertbutton: {
label: 'Alert button',
category: 'static',
rules: [],
schema: {
buttonLabel: 'Alert',
type: 'button',
onClick() {
alert('Test')
}
},
// ...
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Here's an example how you can subscribe to element events when using schema:
(schema tab) https://vueform.com/docs/subscribing-to-events#subscribing-to-events-1
So the syntax is: