Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22397040
simple-form-field.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
2 KB
Referenced Files
None
Subscribers
None
simple-form-field.ts
View Options
/* eslint @typescript-eslint/no-unused-vars: off */
import
{
FormData
,
FormDataValue
}
from
"../form-types.js"
;
import
{
Context
}
from
"koa"
;
import
{
predicates
}
from
"@sealcode/ts-predicates"
;
import
{
FieldParseResult
,
FormField
}
from
"./field.js"
;
import
{
SimpleInput
}
from
"../controls/simple-input.js"
;
import
{
FormControl
,
Textarea
}
from
"../controls/controls.js"
;
import
{
CollectionItem
}
from
"sealious"
;
export
abstract
class
SimpleFormField
<
Required
extends
boolean
,
DefaultControl
extends
FormControl
=
SimpleInput
,
Parsed
=
string
,
>
extends
FormField
<
Required
,
Parsed
,
DefaultControl
>
{
predicate
=
predicates
.
string
;
public
placeholder
!:
string
;
constructor
(
required
:
Required
,
public
type
:
string
=
"text"
)
{
super
(
required
);
}
async
sealiousValueToForm
(
_ctx
:
Context
,
value
:
unknown
)
:
Promise
<
FormDataValue
>
{
if
(
value
===
null
)
{
return
""
;
}
// eslint-disable-next-line @typescript-eslint/no-base-to-string
return
String
(
value
);
}
setPlaceholder
(
placeholder
:
string
)
{
this
.
placeholder
=
placeholder
;
return
this
;
}
}
export
class
TextBasedSimpleField
<
Required
extends
boolean
,
DefaultControl
extends
FormControl
=
SimpleInput
,
>
extends
SimpleFormField
<
Required
,
DefaultControl
,
string
|
null
>
{
async
parse
(
_
:
Context
,
raw_value
:
FormDataValue
)
:
Promise
<
FieldParseResult
<
string
>>
{
return
{
// eslint-disable-next-line @typescript-eslint/no-base-to-string
parsed_value
:
(
raw_value
||
""
).
toString
(),
parsable
:
true
,
error
:
null
,
};
}
async
parsedToSealious
(
value
:
string
)
:
Promise
<
string
>
{
return
value
||
""
;
}
async
postSealiousCreate
(
_ctx
:
Context
,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_created_item
:
CollectionItem
<
any
>
,
_formData
:
FormData
)
:
Promise
<
void
>
{}
async
postSealiousEdit
(
_ctx
:
Context
,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_edited_item
:
CollectionItem
<
any
>
,
_formData
:
FormData
)
:
Promise
<
void
>
{}
getControl
()
:
DefaultControl
{
return
new
Textarea
(
this
,
{
label
:
this
.
label
||
this
.
name
,
type
:
this
.
type
,
})
as
unknown
as
DefaultControl
;
}
public
getEmptyValue
()
:
string
{
return
""
;
}
}
export
class
NumberBasedSimpleField
<
Required
extends
boolean
,
DefaultControl
extends
FormControl
=
SimpleInput
,
>
extends
SimpleFormField
<
Required
,
DefaultControl
,
number
>
{
async
parse
(
_
:
Context
,
raw_value
:
FormDataValue
)
:
Promise
<
FieldParseResult
<
number
>>
{
return
{
parsed_value
:
parseFloat
(
raw_value
as
string
)
||
0
,
parsable
:
true
,
error
:
null
,
};
}
async
parsedToSealious
(
value
:
number
)
:
Promise
<
number
|
undefined
>
{
return
value
||
0
;
}
async
postSealiousCreate
()
:
Promise
<
void
>
{}
async
postSealiousEdit
()
:
Promise
<
void
>
{}
getControl
()
:
DefaultControl
{
return
new
SimpleInput
(
this
,
{
label
:
this
.
label
||
this
.
name
,
type
:
this
.
type
,
})
as
unknown
as
DefaultControl
;
}
public
getEmptyValue
()
:
number
{
return
0
;
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:04 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1198094
Default Alt Text
simple-form-field.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline