# Preceding and trailing spaces are ignored with text input

**URL:** <https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735>\
**Category:** Dashboard\
**Created:** [15 February 2020 05:08 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735 "2020-02-15T05:08:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [15 February 2020 05:08 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/1 "2020-02-15T05:08:01Z")

</div>

All,

It appears that preceding spaces or trailing spaces are ignored in a text input.  
This becomes an issue when we do a 'password entry'  
There is also no trigger on the output when a space is entered.

Example code

```auto
[{"id":"de2de0af.b6406","type":"ui_text_input","z":"37e2c67c.85274a","name":"","label":"","tooltip":"","group":"668d9db5.aab0e4","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"100","topic":"","x":340,"y":280,"wires":[["17f4886.d747c78"]]},{"id":"9dbeea4a.9fd778","type":"ui_text_input","z":"37e2c67c.85274a","name":"","label":"","tooltip":"","group":"668d9db5.aab0e4","order":1,"width":0,"height":0,"passthru":true,"mode":"password","delay":"100","topic":"","x":360,"y":330,"wires":[["e86ed49d.f07ec8"]]},{"id":"17f4886.d747c78","type":"debug","z":"37e2c67c.85274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":640,"y":280,"wires":[]},{"id":"e86ed49d.f07ec8","type":"debug","z":"37e2c67c.85274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":640,"y":330,"wires":[]},{"id":"668d9db5.aab0e4","type":"ui_group","name":"Group 1","tab":"1cec7880.5a4688","order":1,"disp":true,"width":6},{"id":"1cec7880.5a4688","type":"ui_tab","z":"","name":"Example entry","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2c8577390813fa1df9466120c73ba4f3becebd2.png)

As you can see in above example, we entered the following  
' 3 spaces ' (Not the '')

But the payload out of the function is in both cases

```auto
{"payload":"3 spaces","socketid":"XrYwAW7CPErPnN2WAAAJ","_msgid":"434e6646.6207c8"}

```

any spaces between characters are captured.  
This causes me grief as I use the password entry and compare this with a fixed entry.  
The user thinks he entered 14 characters, but the payload only presents 8 characters.

If the entry is made only out of spaces, then no payload is delivered out of the text input function

Any way to get around this?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 February 2020 09:19 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/2 "2020-02-15T09:19:38Z")

</div>

Advise users not to use spaces ?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [15 February 2020 09:24 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/3 "2020-02-15T09:24:40Z")

</div>

😂... but seriously, if the input is trimming whitespace by default, it does feel like there should be an option to not do that. It isn't for us to decide what is valid input or not.

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [15 February 2020 09:26 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/4 "2020-02-15T09:26:21Z")

</div>

Dceejay,

Same method as telling people not to push a button. They will anyway, so as a coder we need to prevent 'stupidity' so the suggestion is nice, but the practicality does not work.

Thanks for your feedback though

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [15 February 2020 09:27 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/5 "2020-02-15T09:27:55Z")

</div>

@knolleary

Agree, an option 'tick' box would be great

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 February 2020 09:32 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/6 "2020-02-15T09:32:54Z")

</div>

PR very welcome

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [15 February 2020 11:11 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/7 "2020-02-15T11:11:03Z")

</div>

@dceejay

I am sorry, I am not a person that talks abbreviations so do not comprehend your comment.  
PR = Public Relations??

Will have a look if I can decipher the original code and see where I can fix this.

Any guidance will be appreciated as my JS (java script) knowledge is well below your level

Thanks

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 February 2020 12:47 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/8 "2020-02-15T12:47:13Z")

</div>

Have you thought about using the ui-form's 'password' type?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 February 2020 16:21 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/9 "2020-02-15T16:21:16Z")

</div>

So it turns out that this is the default behaviour of angular-material text input boxes... they perform a trim() of any input. There is an optional parameter that can be added to the input tag `ng-trim="false"` that turns that off.

I guess the next question is do we really need it optional ? should not-trimmed just be the way it should be (as was expected) ?

PS : PR = Pull Request - a fix to the code submitted by someone.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [15 February 2020 16:37 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/10 "2020-02-15T16:37:04Z")

</div>

I agree, any non intentional (happening behind the scenes) data manipulation is confusing. And who knows there will be a time where passwords could be a little poem and totally valid - and the white spaces in [dada](https://en.m.wikipedia.org/wiki/Dada) poems count.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 March 2020 16:37 UTC](https://discourse.nodered.org/t/preceding-and-trailing-spaces-are-ignored-with-text-input/21735/11 "2020-03-16T16:37:05Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
