Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  124] [ 1]  / answers: 1 / hits: 16929  / 6 Years ago, wed, november 28, 2018, 12:00:00

I have a component called TextInput.vue, and inside I created a div.


<div ts-text-input :ts-text-input-filled="setFilledAttribute && !!value"
:ts-text-input-not-valid="!valueValid">

<input :value="value" @input="setValue" @keyup.enter="enterClicked" :placeholder="placeholder" :title="title">


what I wanted to do now is that to disable some spaces inside the input box so that the user is unable to type in with spaces/spacebar (like, e.g., username input box)


Here is what I have done; I try to use the function trim(), but it seems I can't still fix it.


in the computed function


    computed: {
value: function() {
const {valueGetter, valueGetterOptions} = this,
getter = this.$store.getters[valueGetter];
value.trim();
return valueGetterOptions ? getter(valueGetterOptions) : getter;
},

Any hints would be helpful. thanks. (sorry for my bad English)


More From » vue.js

 Answers
15

You can directly prevent that the user adds a white space to your input field. preventDefault() tells the user agent that the default action should not be taken as it normally would be.


<input @keydown.space="(event) => event.preventDefault()">

Or to make it even shorter (as Sovalina pointed out):


<input @keydown.space.prevent>

[#53021] Saturday, November 24, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiej

Total Points: 294
Total Questions: 95
Total Answers: 97

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;