Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F8922073
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
{
BaseContext
}
from
"koa"
;
import
{
tempstream
}
from
"tempstream"
;
import
{
FormField
,
PickFromListField
}
from
"../field"
;
import
{
FormData
}
from
"../form"
;
import
{
FormFieldsList
}
from
"../form-fields-list"
;
import
{
FormFieldControl
}
from
"./controls"
;
export
class
Dropdown
extends
FormFieldControl
{
constructor
(
public
fieldname
:
string
,
public
options
:
{
label
:
string
;
autosubmit
?:
boolean
;
autocomplete
?:
boolean
;
}
=
{
label
:
fieldname
,
autosubmit
:
false
,
autocomplete
:
true
,
}
)
{
super
([
fieldname
]);
}
areFieldNamesValid
(
fields
:
FormField
[])
{
return
(
super
.
areFieldNamesValid
(
fields
)
&&
FormFieldsList
.
getField
(
fields
,
this
.
fieldname
)
instanceof
PickFromListField
);
}
_render
(
ctx
:
BaseContext
,
fields
:
FormField
[],
data
:
FormData
)
{
// safe to disable this as isValidFieldName takes care of checking if the field is of this type
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const
field
=
FormFieldsList
.
getField
(
fields
,
this
.
fieldname
)
as
PickFromListField
;
const
picked_value
=
data
.
values
[
field
.
name
]
||
""
;
const
id
=
field
.
name
;
return
tempstream
/* HTML */
`<label for="
${
id
}
">
${
this
.
options
.
label
}
</label
><select
name="
${
this
.
fieldnames
}
"
id="
${
id
}
"
${
this
.
options
.
autosubmit
?
`onchange='this.form.submit()'`
:
""
}
${
!
this
.
options
.
autocomplete
?
`autocomplete="off"`
:
""
}
>
${
Promise
.
resolve
(
field
.
generateOptions
(
ctx
)).
then
((
options
)
=>
Object
.
entries
(
options
).
map
(
([
value
,
text
])
=>
`<option value="
${
value
}
"
${
(
value
||
""
)
==
picked_value
?
"selected"
:
""
}
>
${
text
}
</option>`
)
)
}
</select>`
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Sep 20, 14:14 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
932669
Default Alt Text
dropdown.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment