Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7112528
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
{
tempstream
}
from
"tempstream"
;
import
{
attribute
}
from
"../../sanitize"
;
import
{
PickFromListField
}
from
"../fields/field"
;
import
{
FormDataValue
}
from
"../form"
;
import
{
SimpleInput
}
from
"./simple-input"
;
export
class
Dropdown
extends
SimpleInput
<
string
|
null
>
{
constructor
(
public
field
:
PickFromListField
<
boolean
>
,
public
options
:
{
label
:
string
;
autosubmit
?:
boolean
;
autocomplete
?:
boolean
;
}
=
{
label
:
field
.
name
,
autosubmit
:
false
,
autocomplete
:
true
,
}
)
{
super
(
field
);
}
async
getInputAttributes
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
,
field_prefix
:
string
,
form_id
:
string
)
:
Promise
<
Record
<
string
,
string
|
boolean
>>
{
const
original
=
await
super
.
getInputAttributes
(
ctx
,
data
,
field_prefix
,
form_id
);
return
{
...
original
,
...
Object
.
fromEntries
([
...(
this
.
options
.
autosubmit
?
[
[
"onchange"
,
(
original
.
onchange
||
""
)
+
";this.form.submit();"
,
],
]
:
[]),
]),
};
}
async
renderInput
(
ctx
:
Context
,
attributes_str
:
string
,
data
:
Record
<
string
,
FormDataValue
>
)
:
Promise
<
FlatTemplatable
>
{
const
{
parsed
:
picked_value
}
=
await
this
.
field
.
getValue
(
ctx
,
data
);
return
/* HTML */
tempstream
`<select
${
attributes_str
}
>
${
// 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
Thu, Jul 3, 19:11 (6 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
793750
Default Alt Text
dropdown.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment