Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010207
pick-from-list.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
pick-from-list.ts
View Options
import
{
is
,
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
Context
}
from
"koa"
;
import
type
{
DropdownOption
}
from
"../controls/dropdown.js"
;
import
{
FormFieldValidationResponse
}
from
"./field.js"
;
import
{
SimpleFormField
}
from
"./simple-form-field.js"
;
export
class
PickFromListField
<
Required
extends
boolean
>
extends
SimpleFormField
<
Required
>
{
constructor
(
public
required
:
Required
,
public
generateOptions
:
(
ctx
:
Context
)
=>
Promise
<
DropdownOption
[]
>
,
public
customValidation
:
(
ctx
:
Context
,
value
:
unknown
,
instance
:
PickFromListField
<
Required
>
)
=>
Promise
<
FormFieldValidationResponse
>
=
(
ctx
,
value
,
instance
)
=>
instance
.
valueInList
(
ctx
,
value
)
)
{
super
(
required
);
}
predicate
=
predicates
.
string
;
public
isValueValid
(
ctx
:
Context
,
value
:
string
)
:
Promise
<
FormFieldValidationResponse
>
{
return
this
.
customValidation
(
ctx
,
value
,
this
);
}
async
valueInList
(
ctx
:
Context
,
value
:
unknown
)
:
Promise
<
FormFieldValidationResponse
>
{
const
options
=
await
this
.
generateOptions
(
ctx
);
if
(
!
is
(
value
,
predicates
.
string
))
{
return
{
valid
:
false
,
message
:
"not a string"
};
}
if
(
this
.
required
&&
!
options
.
map
((
o
)
=>
o
.
value
).
includes
(
value
))
{
return
{
valid
:
false
,
message
:
`"
${
value
}
" is not one of the options`
,
};
}
return
{
valid
:
true
,
message
:
""
};
}
public
getEmptyValue
()
:
string
{
return
""
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625902
Default Alt Text
pick-from-list.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment