Why are multiple spaces in html hidden input value treated as one? - html

It is obvious, that consecutive whitespaces are rendered as one space in HTML. But why does this apply to the value attribute of hidden input fields ? And how to overcome this problem ?
E.g. the markup <input type="hidden" name="var" value="a b"> will result in the value being a b (with only one space).
Note : I'm using PrestaShop.
Edit: The problem was the following: Prestashop has an option Advanced Parameters - Performance - Combine, compress and cache - Minify HTML, that represents multiple whitespaces as one, even in attribute values. It can be considered a bug, since multiple whitespaces are significatif in html attributes.

Normal space (not non breaking space or ) is , you should be able to add double spaces with it.
Unicode-Table

Not sure if this works, but have you tried instead of a normal space?

Related

How to limit simple form input to 50 characters

Is it possible to limit a simple form input to only 50 characters without javascript?
I have used the max_length attribute, however this includes blank spaces which is not what i want.
I've attempted to use pattern (as suggested on another post), but i can't seem to get that to work either.
Thanks
I don't know why you don't want it to include blanks.
Usually I use max_length including blanks and leave it to the user to trim their excess whitespace. I'm not disagreeing, I honestly don't know what your requirement is.
If you want to allow leading and trailing whitespace, but are willing to leave it to the user to replace excess whitespace within the text to one whitespace character then this is the pattern you want:
<input pattern="^\s*.{0,50}\s*$">
Sometimes for multiline regular expressions, \A is used instead of ^ and \z is used instead of $, but I'm not sure HTML supports that in their regular expressions.

Format the display of a field

I'm aware that parsing numbers with pure CSS is impossible. But as in my case I know for certain that the input will always be in a specific way, is it possible to change the display of an input field based on the count of characters in it?
e.G. I want '123450' to be displayed as '1,234.50' - or if it were 'abcdef' it should become 'a,bcd.ef'.
So, I would like a rule that says: from right to left: after the second char display a dot, after the fifth and eight char display a comma.
Is that possible?
Example:
<input type="text" class="unformatted" value="123456" />
Should display like
<input type="text" class="formatted" vaulue="1,234.56" />
while still retaining its original value 123456.
What you're asking is not possible with pure CSS. The smallest you can go with CSS is the single HTML tag, you cannot go deeper than that.
Individual lines of text cannot be selected or altered, as they are seen as a whole by CSS engine.
With a little help from JavaScript, however, this can be easily done.

Filling out spaces between html attributes in order to simplify editing in block mode

I would like to fill the space between html attributes regularly in order to simplify editing in block mode.
Example:
<p><input type="a" name="a" value="foo a"></p>
<p><input type="ab" name="ab" value="ab bar"></p>
<p><input type="abc" name="abc" value="baz abc"></p>
Select the three inputs in visual block mode and do some magic.
Output:
<p><input type="a" name="a" value="foo a" ></p>
<p><input type="ab" name="ab" value="ab bar" ></p>
<p><input type="abc" name="abc" value="baz abc"></p>
(Preferably without filling out the spaces between values.)
How do I do that?
Edit: And a way back (after editing) would be nice, too.
You can do this with the Align plugin:
:AlignCtrl mIp1P0=l
:Align \i\+=
or build a mapping with it:
map <unique> <SID>WS <Plug>AlignMapsWrapperStart
nmap <unique> <SID>WE <Plug>AlignMapsWrapperEnd
map <silent> <script> <Leader>aa <SID>WS:AlignCtrl mIp1P0=l<CR><CR>:'a,'zAlign \i\+\s*=<CR><SID>WE
There's also an alternative to Align called Tabularize.
You can use an external tool for that, I use astyle for my C/C++ coding, to make it automatic I inserted the following in my ~/.vimrc file:
if filereadable("/usr/bin/astyle")
silent! %!astyle
endif
You can search for Tidy if it meets your needs.
Obs.: With :%! you pass all the code to the external tool "!, for specific selection '<,'>! should be used.
Now you can map a shortcut to this command.
If there only one space between attributes you can make that :
:s/"\s/"\t/g
You can see more here.
What kind of edits are you doing in block mode? There is probably an easier way to edit.
Here's an example:
removing type="*":
linewise visually select the block (i.e V})
type :norm WdW
explanation:
When you type : with a visual selection, you should see :'<,'> in the command line. This means do the following command on just the selection
:norm means interpret the following characters in normal mode
W jumps to the beginning of the next Word
dW deletes until the beginning of the following Word
I did have to align words as you describe once for a specific case where it was preferred for readability (it's usually frowned upon). I ended up doing a quick hack to get the job done. In your case, it would look like:
(select block)
:'<,'>s/ / /g
(go to first space after "input")
(note the column number in the lower right (10))
gv (reselect block)
:norm 10ldw (delete
(go to first space after "abc" (because this is the longest value for this column))
(note the column number (21))
:norm 21ldw
... and so on
If you just want to delete a column, you could just convert 1 space into many, block select the column including some empty spaces on each side, delete, and convert many spaces back to one.
As I said before, this method is very fragile and only possible when spaces are only used to delimit columns. Instead of using :norm on a block, you can also consider making macros or trying to accomplish your editing tasks with find and replace

Why isn't textarea an input[type="textarea"]?

Why is there an element <textarea> instead of <input type="textarea">?
Maybe this is going a bit too far back but…
Also, I’d like to suggest that multiline text fields have a different type (e.g. “textarea") than single-line fields ("text"), as they really are different types of things, and imply different issues (semantics) for client-side handling.
– Marc Andreessen, 11 October 1993
So that its value can easily contain quotes and <> characters and respect whitespace and newlines.
The following HTML code successfully pass the w3c validator and displays <,> and & without the need to encode them. It also respects the white spaces.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Yes I can</title>
</head>
<body>
<textarea name="test">
I can put < and > and & signs in
my textarea without any problems.
</textarea>
</body>
</html>
A textarea can contain multiple lines of text, so one wouldn't be able to pre-populate it using a value attribute.
Similarly, the select element needs to be its own element to accommodate option sub-elements.
It was a limitation of the technology at the time it was created. My answer copied over from Programmers.SE:
From one of the original HTML drafts:
NOTE: In the initial design for forms, multi-line text fields were
supported by the Input element with TYPE=TEXT. Unfortunately, this
causes problems for fields with long text values. SGML's default
(Reference Quantity Set) limits the length of attribute literals to
only 240 characters. The HTML 2.0 SGML declaration increases the limit
to 1024 characters.
I realize this is an older post, but thought this might be helpful to anyone wondering the same question:
While the previous answers are no doubt valid, there is a more simple reason for the distinction between textarea and input.
As mentioned previously, HTML is used to describe and give as much semantic structure to web content as possible, including input forms. A textarea may be used for input, however a textarea can also be marked as read only via the readonly attribute. The existence of such an attribute would not make any sense for an input type, and thus the distinction.

HTML: <textarea>-Tag: How to correctly escape HTML and JavaScript content displayed in there?

I have a HTML Tag <textarea>$FOO</textarea> and the $FOO Variable will be filled with arbitrary HTML and JavaScript Content, to be displayed and edited within the textarea. What kind of "escaping" do I neet to apply to $FOO?
I first tought of escaping it HTML but this didnt work (as I will then get shown not the original HTML Code of $FOO but rather the escaped content. This is of course not what I want: I want to be displayed the unescaped HTML/JS Content of the variable...
Is it impossible to display HTML Content within a <textarea> tag and also allow it to be editable as full HTML?
thanks
jens
I first tought of escaping it HTML
Yes, that's right. The contents of a <textarea> are no different from the contents of any other element like a <span> or a <p>: if you want to put some text inside you must HTML-escape any < or & characters in it to < and & respectively.
Browsers do tend to give you more leeway with fault markup in <textarea>​s, in that the fallback for invalid unescaped < symbols is to render them as text instead of tags, but that doesn't make it any less wrong or dangerous (for XSS).
but this didnt work
Please post what you did that didn't work. HTML-escaping is definitely the right thing.
You need to replace the special character of HTML with character references (either numerical character references or entity references), in textarea, at least &, < and >.