Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188968
checkboxed-list-input.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
checkboxed-list-input.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Context
}
from
"koa"
;
import
{
tempstream
}
from
"tempstream"
;
import
{
getRequiredClass
,
inputWrapper
}
from
"../../utils/input-wrapper"
;
import
{
ChekboxedListField
}
from
"../fields/field"
;
import
{
FormDataValue
}
from
"../form"
;
import
{
FormFieldControl
}
from
"./controls"
;
export
class
CheckboxedListInput
extends
FormFieldControl
{
constructor
(
public
field
:
ChekboxedListField
,
public
options
:
{
label
:
string
}
=
{
label
:
field
.
name
}
)
{
super
([
field
]);
}
async
render
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
)
{
const
{
parsed
:
pickedValues
}
=
await
this
.
field
.
getValue
(
ctx
,
data
);
if
(
!
is
(
pickedValues
,
predicates
.
array
(
predicates
.
string
)))
{
throw
new
Error
(
"picked values is not an array of strings"
);
}
const
[
options
,
isVisible
]
=
await
Promise
.
all
([
this
.
field
.
generateOptions
(
ctx
),
this
.
field
.
isVisible
(
ctx
),
]);
const
{
name
,
required
}
=
this
.
field
;
return
tempstream
/* HTML */
`
${
isVisible
?
Object
.
entries
(
options
).
map
(([
value
,
text
])
=>
inputWrapper
(
[
name
,
getRequiredClass
(
required
)],
/* HTML */
`
<input
type="checkbox"
id="
${
name
}
.
${
value
}
"
name="
${
name
}
.
${
value
}
"
${
pickedValues
.
includes
(
value
)
?
"checked"
:
""
}
/>
<label for="
${
name
}
.
${
value
}
">
${
text
}
</label>
`
)
)
:
""
}
`
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 08:39 (7 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
806062
Default Alt Text
checkboxed-list-input.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment