Skip to content

Commit 6f64be7

Browse files
committed
Add PluginForm component
1 parent fd22417 commit 6f64be7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

rdmo/projects/assets/js/project/components/areas/Dashboard.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { TileGrid } from '../helper'
33

44
import Tooltip from 'rdmo/core/assets/js/_bs53/components/Tooltip'
55

6+
import PluginForm from '../helper/PluginForm'
7+
68
const Dashboard = () => {
79
const [tileSize, setTileSize] = useState('normal')
810

@@ -23,6 +25,8 @@ const Dashboard = () => {
2325
{ title: 'Tile 6', content: <p>Content 6</p> },
2426
]
2527

28+
const html = '<form><input class="form-control mb-3" type="text" name="input" /><button type="submit" class="btn btn-primary">Submit</button></form>'
29+
2630
return (
2731
<div>
2832
<h1>{gettext('Dashboard')}</h1>
@@ -39,6 +43,8 @@ const Dashboard = () => {
3943
<span>TOOLTIP</span>
4044
</Tooltip>
4145
</div>
46+
47+
<PluginForm html={html} />
4248
</div>
4349
</div>
4450
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useRef, useEffect } from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
import Html from 'rdmo/core/assets/js/components/Html'
5+
6+
const PluginForm = ({ html }) => {
7+
const ref = useRef(null)
8+
9+
useEffect(() => {
10+
if (ref.current) {
11+
const form = ref.current.querySelector('form')
12+
13+
const submitForm = (event) => {
14+
event.preventDefault()
15+
16+
const formData = new FormData(form)
17+
console.log(formData.get('input'))
18+
}
19+
20+
// add event listener to form
21+
form.addEventListener('submit', submitForm)
22+
23+
// cleanup on unmount
24+
return () => form.removeEventListener('submit', submitForm)
25+
}
26+
}, [])
27+
28+
return <div ref={ref}><Html html={html} /></div>
29+
}
30+
31+
PluginForm.propTypes = {
32+
html: PropTypes.string
33+
}
34+
35+
export default PluginForm

0 commit comments

Comments
 (0)