Answer the question
In order to leave comments, you need to log in
How to dynamically trim spaces in material input?
AngularJS framework question. I am using input from the material library. The user of my code sequentially enters into the input:
1. a few spaces +
2. a few characters +
3. again a few spaces
Then he clicks on the submit button. As a result, only characters are output to the console, without leading and trailing spaces. Fine! This is exactly the behavior I want.
But I would like the leading and trailing spaces to:
1. disappear from the input after losing focus
2. immediately disappear from the input field immediately pressing the key (or copy-paste)
3. the user would not be allowed to enter them at all
Any of the three options listed suited me would. Please help me implement this.
LIVE DEMO
<md-input-container>
<label>Title</label>
<input ng-model="$ctrl.pass">
</md-input-container>
<button ng-click="$ctrl.change()">submit</button>
class HomeCtrl {
constructor() {
this.pass = null;
this.change = function() {
setTimeout(_ => {
console.log(this.pass, 'length:', this.pass.length)
});
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question