Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F21589235
enum.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
853 B
Referenced Files
None
Subscribers
None
enum.ts
View Options
import
{
Field
,
Context
,
App
}
from
"../../../main.js"
;
type
Props
<
S
>
=
S
[]
|
((
app
:
App
)
=>
S
[]);
/** Allows only a specified set of values.
*
* **Params**:
* - `allowed_values` - `Array<any>` - list of acceptable values
*/
export
default
class
Enum
<
S
>
extends
Field
<
string
>
{
typeName
=
"enum"
;
allowed_values
:
Props
<
S
>
;
constructor
(
allowed_values
:
Props
<
S
>
)
{
super
();
this
.
allowed_values
=
allowed_values
;
}
getAllowedValues
(
app
:
App
)
:
S
[]
{
return
this
.
allowed_values
instanceof
Function
?
this
.
allowed_values
(
app
)
:
this
.
allowed_values
;
}
async
isProperValue
(
context
:
Context
,
value
:
S
)
{
if
(
this
.
getAllowedValues
(
context
.
app
).
includes
(
value
))
{
return
Field
.
valid
();
}
else
{
return
Field
.
invalid
(
context
.
app
.
i18n
(
"invalid_enum"
,
[
this
.
getAllowedValues
(
context
.
app
).
join
(),
])
);
}
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 7, 17:08 (13 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1181973
Default Alt Text
enum.ts (853 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline