Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7112817
dropdown.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
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
text/x-java
Expires
Fri, Jul 4, 06:23 (20 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
799166
Default Alt Text
dropdown.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment