mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(input): ion-input accepts any string value (#24606)
Resolves #19884
This commit is contained in:
@@ -231,6 +231,17 @@ export class Input implements ComponentInterface {
|
||||
*/
|
||||
@Watch('value')
|
||||
protected valueChanged() {
|
||||
if (this.nativeInput) {
|
||||
/**
|
||||
* Assigning the native input's value on attribute
|
||||
* value change, allows `ionInput` implementations
|
||||
* to override the control's value.
|
||||
*
|
||||
* Used for patterns such as input trimming (removing whitespace),
|
||||
* or input masking.
|
||||
*/
|
||||
this.nativeInput.value = this.getValue();
|
||||
}
|
||||
this.emitStyle();
|
||||
this.ionChange.emit({ value: this.value == null ? this.value : this.value.toString() });
|
||||
}
|
||||
|
||||
20
core/src/components/input/test/masking/e2e.ts
Normal file
20
core/src/components/input/test/masking/e2e.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { newE2EPage } from '@stencil/core/testing';
|
||||
|
||||
test('input: masking', async () => {
|
||||
const page = await newE2EPage({
|
||||
url: '/src/components/input/test/masking?ionic:_testing=true'
|
||||
});
|
||||
|
||||
const inputTrimmed = await page.find('#inputTrimmed');
|
||||
|
||||
await inputTrimmed.click();
|
||||
|
||||
await page.keyboard.type('S p a c e s');
|
||||
|
||||
const currentValue = await page.$eval('#inputTrimmed', (el: any) => {
|
||||
return el.value;
|
||||
});
|
||||
|
||||
expect(currentValue).toEqual('Spaces');
|
||||
|
||||
});
|
||||
40
core/src/components/input/test/masking/index.html
Normal file
40
core/src/components/input/test/masking/index.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Input - Masking</title>
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
|
||||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
|
||||
<script src="../../../../../scripts/testing/scripts.js"></script>
|
||||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
|
||||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<ion-app>
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>Input - Masking</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
<ion-item>
|
||||
<ion-label position="stacked">Input with trimming</ion-label>
|
||||
<ion-input id="inputTrimmed" placeholder="Trimmed Input" />
|
||||
</ion-item>
|
||||
</ion-content>
|
||||
|
||||
<script>
|
||||
document
|
||||
.getElementById('inputTrimmed')
|
||||
.addEventListener('ionInput', e => {
|
||||
e.target.value = e.target.value.trim();
|
||||
});
|
||||
</script>
|
||||
</ion-app>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user