Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7317382
simple-input.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
simple-input.ts
View Options
import
{
Context
}
from
"koa"
;
import
{
FormField
}
from
"../fields/field"
;
import
{
FormDataValue
}
from
"../form"
;
import
{
FormFieldControl
}
from
"./controls"
;
export
class
SimpleInput
extends
FormFieldControl
{
constructor
(
public
field
:
FormField
,
public
options
:
{
id
?:
string
;
label
?:
string
;
autocomplete
?:
boolean
;
hide_errors
?:
boolean
;
type
?:
|
"color"
|
"date"
|
"email"
|
"file"
|
"month"
|
"number"
|
"password"
|
"search"
|
"tel"
|
"text"
|
"time"
|
"url"
|
"week"
;
value
?:
string
;
placeholder
?:
string
;
readonly
?:
boolean
;
step
?:
number
;
}
=
{}
)
{
super
([
field
]);
}
async
render
<
Fields
extends
Record
<
string
,
FormField
>>
(
ctx
:
Context
,
data
:
Record
<
string
,
FormDataValue
>
)
{
const
id
=
this
.
options
.
id
||
this
.
field
.
name
;
const
label
=
this
.
options
.
label
||
this
.
field
.
name
;
const
type
=
this
.
options
.
type
||
"text"
;
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const
{
parsed
,
raw
,
valid
,
message
}
=
await
this
.
field
.
getValue
(
ctx
,
data
);
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const
placeholder
=
this
.
options
.
placeholder
||
type
;
const
readonly
=
this
.
options
.
readonly
||
false
;
const
required
=
this
.
field
.
required
;
return
/* HTML */
`<div class="form-input form-input__wrapper">
<label for="
${
id
}
">
${
label
}
</label>
<input
id="
${
id
}
"
type="
${
type
}
"
name="
${
this
.
field
.
name
}
"
value="
${
!
valid
&&
raw
?
raw
.
toString
()
:
parsed
!==
undefined
&&
parsed
!==
null
?
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
((
parsed
as
any
)
?
.
toString
()
as
string
)
||
""
:
""
}
"
placeholder="
${
placeholder
}
"
${
readonly
?
"readonly"
:
""
}
${
required
?
"required"
:
""
}
${
!
this
.
options
.
autocomplete
?
`autocomplete="off"`
:
""
}
${
this
.
options
.
step
?
`step="
${
this
.
options
.
step
}
"`
:
""
}
/>
${
~
valid
&&
!
this
.
options
.
hide_errors
?
`<div class="input__error">
${
message
}
</div>`
:
""
}
</div>`
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Jul 13, 04:39 (1 d, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
821769
Default Alt Text
simple-input.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment