Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996509
submit-on-input.stimulus.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
submit-on-input.stimulus.ts
View Options
/* eslint-disable @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-unsafe-assignment */
import
{
Controller
}
from
"stimulus"
;
import
{
throttle
}
from
"throttle-debounce"
;
export
default
class
SubmitOnInput
extends
Controller
<
HTMLTextAreaElement
>
{
sendValues
:
()
=>
void
;
connect
()
{
this
.
sendValues
=
throttle
(
500
,
()
=>
{
const
component_index
=
this
.
element
.
closest
(
".jdd-editor__component-block"
)
?
.
getAttribute
(
"data-component-index"
)
||
null
;
if
(
component_index
==
null
)
{
// not an input within a JDD component editor
this
.
element
.
closest
(
"form"
)
?
.
requestSubmit
();
return
;
}
// During this automatic submit, we force idiomorph to only update the components edited by this input.
const
updateOnlyPreview
=
(
event
:
BeforeUnloadEvent
)
=>
{
const
target
=
event
.
target
as
HTMLDivElement
;
if
(
[
"component-arguments"
,
"component-preview__header"
,
].
includes
(
target
.
id
)
||
(
target
.
parentElement
?
.
classList
.
contains
(
"jdd-container"
)
&&
!
target
.
classList
.
contains
(
"component-number-"
+
component_index
))
)
{
event
.
preventDefault
();
}
};
document
.
addEventListener
(
"turbo:before-morph-element"
,
updateOnlyPreview
);
this
.
element
.
closest
(
"form"
)
?
.
requestSubmit
();
const
after_submit
=
()
=>
{
document
.
removeEventListener
(
"turbo:before-morph-element"
,
updateOnlyPreview
);
document
.
removeEventListener
(
"turbo:morph"
,
after_submit
);
};
document
.
addEventListener
(
"turbo:morph"
,
after_submit
);
},
{
noTrailing
:
false
}
);
}
makePermanent
()
{
// this prevents morphing from overwriting the input value with previous half-dane values - https://github.com/hotwired/turbo/issues/1199
this
.
element
.
setAttribute
(
"data-turbo-permanent"
,
""
);
}
makeNotPermanent
()
{
this
.
element
.
removeAttribute
(
"data-turbo-permanent"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:05 (12 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557293
Default Alt Text
submit-on-input.stimulus.ts (1 KB)
Attached To
Mode
rJDDE jdd-editor
Attached
Detach File
Event Timeline
Log In to Comment