Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F8922408
checkbox-group.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
checkbox-group.ts
View Options
import
{
Context
}
from
"koa"
;
import
{
FlatTemplatable
}
from
"tempstream"
;
import
{
EnumMultipleField
,
FormField
}
from
"../fields/field"
;
import
{
ProxyFormField
}
from
"../fields/proxy-field"
;
import
{
FormDataValue
,
FormMessage
}
from
"../form"
;
import
{
CheckboxWithValue
}
from
"./checkbox"
;
import
{
FieldGroup
,
FormFieldControl
}
from
"./controls"
;
export
type
DefaultCheckboxOptions
=
{
id
?:
string
;
label
?:
string
;
hide_errors
?:
boolean
;
readonly
?:
boolean
;
name
?:
string
;
checkboxNameToLabel
?:
(
name
:
string
)
=>
string
;
classes
?:
string
[];
};
export
class
CheckboxGroup
<
Options
extends
DefaultCheckboxOptions
=
DefaultCheckboxOptions
>
extends
FormFieldControl
{
constructor
(
public
field
:
EnumMultipleField
<
readonly
string
[],
boolean
>
,
public
options
:
Options
=
{}
as
Options
)
{
super
([
field
]);
}
wrapGroup
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
,
messages
:
FormMessage
[],
field_prefix
:
string
,
form_id
:
string
,
checkboxes
:
CheckboxWithValue
[],
show_field_errors
:
boolean
)
:
Promise
<
FlatTemplatable
>
{
return
new
FieldGroup
(
checkboxes
,
{
label
:
this
.
options
.
label
,
classes
:
[
...(
this
.
options
.
classes
||
[]),
"field-group--checkboxes"
,
],
}).
render
(
ctx
,
data
,
messages
,
field_prefix
,
form_id
,
show_field_errors
);
}
async
render
<
Fields
extends
Record
<
string
,
FormField
>>
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
,
messages
:
FormMessage
[],
field_prefix
:
string
,
form_id
:
string
,
show_field_errors
:
boolean
)
:
Promise
<
FlatTemplatable
>
{
const
{
parsed
:
values
}
=
await
this
.
field
.
getValue
(
ctx
,
data
);
const
checkboxes
=
this
.
field
.
options
.
map
(
(
option
)
=>
new
CheckboxWithValue
(
new
ProxyFormField
(
false
,
this
.
field
.
name
,
false
,
values
.
includes
(
option
)
),
{
id
:
this
.
field
.
name
+
"__"
+
option
,
label
:
(
this
.
options
.
checkboxNameToLabel
||
((
s
:
string
)
=>
s
)
)(
option
),
},
option
)
);
return
this
.
wrapGroup
(
ctx
,
data
,
messages
,
field_prefix
,
form_id
,
checkboxes
,
show_field_errors
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Sep 20, 14:34 (23 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
930061
Default Alt Text
checkbox-group.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment