Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22396982
dropdown.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
dropdown.ts
View Options
import
{
Context
}
from
"koa"
;
import
{
attribute
}
from
"../../sanitize"
;
import
{
getRequiredClass
,
inputWrapper
}
from
"../../utils/input-wrapper"
;
import
{
FormField
,
PickFromListField
}
from
"../fields/field"
;
import
{
FormDataValue
}
from
"../form"
;
import
{
FormFieldControl
}
from
"./controls"
;
export
class
Dropdown
extends
FormFieldControl
{
constructor
(
public
field
:
PickFromListField
,
public
options
:
{
label
:
string
;
autosubmit
?:
boolean
;
autocomplete
?:
boolean
;
}
=
{
label
:
field
.
name
,
autosubmit
:
false
,
autocomplete
:
true
,
}
)
{
super
([
field
]);
}
async
render
<
Fields
extends
Record
<
string
,
FormField
>>
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
)
{
const
{
parsed
:
picked_value
}
=
await
this
.
field
.
getValue
(
ctx
,
data
);
const
name
=
this
.
field
.
name
;
return
inputWrapper
(
[
name
,
getRequiredClass
(
this
.
field
.
required
)],
/* HTML */
`<label for="
${
name
}
">
${
this
.
options
.
label
}
</label
><select
name="
${
this
.
field
.
name
}
"
id="
${
name
}
"
${
this
.
options
.
autosubmit
?
`onchange='this.form.submit()'`
:
""
}
${
!
this
.
options
.
autocomplete
?
`autocomplete="off"`
:
""
}
>
${
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Promise
.
resolve
(
this
.
field
.
generateOptions
(
ctx
)).
then
(
(
options
)
=>
Object
.
entries
(
options
).
map
(
([
value
,
text
])
=>
`<option value="
${
attribute
(
value
)
}
"
${
(
value
||
""
)
==
picked_value
?
"selected"
:
""
}
>
${
text
}
</option>`
)
)
}
</select>`
);
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:02 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200658
Default Alt Text
dropdown.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline