Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188681
checkbox-group.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
checkbox-group.ts
View Options
import
{
FlatTemplatable
}
from
"tempstream"
;
import
{
EnumMultipleField
}
from
"../fields/enum-multiple.js"
;
import
{
ProxyFormField
}
from
"../fields/proxy-field.js"
;
import
{
CheckboxWithValue
}
from
"./checkbox.js"
;
import
{
FieldGroup
}
from
"./field-group.js"
;
import
{
FormControlContext
}
from
"./form-control.js"
;
import
{
FormFieldControl
}
from
"./form-field-control.js"
;
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
(
fctx
:
FormControlContext
,
checkboxes
:
CheckboxWithValue
[]
)
:
Promise
<
FlatTemplatable
>
{
return
new
FieldGroup
(
checkboxes
,
{
label
:
this
.
options
.
label
,
classes
:
[
...(
this
.
options
.
classes
||
[]),
"field-group--checkboxes"
,
],
}).
render
(
fctx
);
}
async
render
(
fctx
:
FormControlContext
)
:
Promise
<
FlatTemplatable
>
{
const
{
parsed
:
values
}
=
await
this
.
field
.
getValue
(
fctx
.
ctx
,
fctx
.
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
),
default_value
:
false
,
},
option
)
);
return
this
.
wrapGroup
(
fctx
,
checkboxes
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 08:26 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
626121
Default Alt Text
checkbox-group.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment