question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: ion-input not updating value if space trimmed equivalent of value changes

See original GitHub issue

Bug Report

Ionic version: [x] 4.11.4

Current behavior: When setting an ion-input’s value to a trimmed version of its previous value, the input does not recognize the value change. Therefore, there is no way to enforce input value trimming while typing inside an ion-input or after leaving an ion-input.

Expected behavior: Setting the value of an ion-input should accept any string and update accordingly.

Steps to reproduce:

  1. Initialize an ion-input on the page.
  2. Listen to the ionInput event.
  3. Inside the inputInput event, set the input’s value to a trimmed version of its own value.

Related code:

JS FIDDLE: https://jsfiddle.net/kpe14jwz/3/

<ion-item>
        <ion-label position="floating">Type here</ion-label>
        <ion-input id="ionInput"></ion-input>
</ion-item>
document.getElementById('ionInput')
.addEventListener('ionInput', (e) => {
	e.target.value = e.target.value.trim();
});

Ionic Info:

N/A. Working out of jsfiddle with CDN.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sprengerstcommented, May 23, 2020

Still an issue in Ionic 5

3reactions
liamdebeasicommented, Nov 11, 2019

Thanks for the issue. This appears to be a regression that appeared in Ionic 4.6.0, so I will mark this as a bug.

Example in Ionic 4.5.0: https://codepen.io/liamdebeasi/pen/RwwBYop Example in Ionic 4.6.0: https://codepen.io/liamdebeasi/pen/YzzjONN

As a temporary workaround you can do something like:

input.addEventListener('ionInput', (e) => {
  window.requestAnimationFrame(() => {
    e.target.value = e.target.value.replace(/[^0-9]/g, '');
  });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - ionic:Change event is not fired on <ion-input> when ...
I am changing input value from one of external javascript file. $('.scoreboardus input').val(200).trigger('onchange');.
Read more >
ion-input: Custom Input Value Type Styling and CSS Properties
ion-input is a wrapper to the HTML input element, with custom value type styling ... The error slot will not be displayed unless...
Read more >
App Rejected - Ion-Input Login Iss… | Apple Developer Forums
I have tested inputting the credentials using a real device and iOS simulator with no issues (including copy/pasting the provided values).
Read more >
How to Trim the Value of Angular's Form Control - Netanel Basal
First, Angular's email validator performs the validation without trimming the value. In some cases, users accidentally add whitespace to the ...
Read more >
SIMION 8.0 Issues/Bugs/Enhancements
if no change has been made. Issue I82 2005-12-10 [gui,resolved] "browse files" on main screen shows directories but no files. Resolved in some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found