I am using the package below to generate a form dynamically:
https://www.npmjs.com/package/react-formio
I have generated a simple button ( not submit button
) using this link ( which have only one button
) https://codesandbox.io/s/cra-react-formio-iy8lz
After building, it creates a JSON. Then, I generate a button using that JSON.
here is my code https://codesandbox.io/s/wandering-frog-s0bzq
I want to show alert
on button click
ReactDOM.render(
<Form
src={{
display: "form",
components: [
{
label: "Click",
action: "event",
showValidations: false,
key: "click",
type: "button",
input: true,
event: "clickEvent"
}
]
}}
clickEvent={() => {
alert("--");
}}
options={{ submitMessage: "", disableAlerts: true, noAlerts: true }}
onSubmit={i => {
alert(JSON.stringify(i.data));
var promise1 = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve("foo");
}, 300);
});
promise1.then(function(value) {
alert(value);
// expected output: "foo"
});
}}
/>,
// <Form src="https://peb3z.sse.codesandbox.io/abc" onSubmit={(i)=>{console.log(i)}} />,
rootElement
);
the event is onAction , no action
components: [
{
label: "Click",
onAction: "event",
showValidations: false,
key: "click",
type: "button",
input: true,
event: "clickEvent"
}
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.