File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
rdmo/projects/assets/js/project/components Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { TileGrid } from '../helper'
33
44import Tooltip from 'rdmo/core/assets/js/_bs53/components/Tooltip'
55
6+ import PluginForm from '../helper/PluginForm'
7+
68const 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 )
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments