Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4122920
ValidatingTextInput.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ValidatingTextInput.js
View Options
const
{
defineComponent
,
h
,
ref
}
=
require
(
'vue'
);
const
{
CdxTextInput
}
=
require
(
'@wikimedia/codex'
);
/**
* A wrapper for a TextInput that uses HTMLInputElement's `checkValidity()` to validate
* the input against any constraints given via HTML attributes (i.e. `required`, or `min=1`).
*
* @todo replace with Codex useNativeValidation composable once available (T373872#10175988)
*/
module
.
exports
=
exports
=
defineComponent
(
{
name
:
'ValidatingTextInput'
,
components
:
{
CdxTextInput
},
emits
:
[
'update:status'
],
setup
(
props
,
{
emit
}
)
{
const
status
=
ref
(
'default'
);
const
messages
=
ref
(
{}
);
/**
* Clear error status when input is valid and emit the `update:messages` event.
*
* @param {Event} e
*/
const
onInput
=
(
e
)
=>
{
if
(
e
.
target
.
checkValidity
()
)
{
status
.
value
=
'default'
;
messages
.
value
=
{};
emit
(
'update:status'
,
status
.
value
,
messages
.
value
);
}
};
/**
* Set error status when input is invalid and emit the `update:messages` event.
*
* @param {Event} e
*/
const
onInvalid
=
(
e
)
=>
{
status
.
value
=
'error'
;
messages
.
value
=
{
error
:
e
.
target
.
validationMessage
};
emit
(
'update:status'
,
status
.
value
,
messages
.
value
);
};
return
{
status
,
messages
,
onInput
,
onInvalid
};
},
render
()
{
return
h
(
CdxTextInput
,
Object
.
assign
(
{},
this
.
$props
,
{
status
:
this
.
status
,
onInput
:
this
.
onInput
,
onInvalid
:
this
.
onInvalid
}
)
);
}
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 19, 05:48 (6 h, 52 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
95/17/64f867c1ea373a7e851da3b36498
Default Alt Text
ValidatingTextInput.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment