can't pass complete text - django

<span>Question:<input type=text value={{QuestionText}} id="question">
Say the text in QuestionText is HOW YOU DOING (note that there is no quotes), but the actual output is the text box filled with only HOW part without the following. How can I get the whole text in the input box? Thank you

Use quotes:
<span>Question:<input type="text" value="{{QuestionText}}" id="question">

You could put quotations to make it look like this:
<span>Question:<input type=text value="{{QuestionText}}" id="question">
Without the quotes, it's only the first word that gets assigned to your value attribute.

Related

HTML input pattern fails

I'm sure I miss something, but can't find the reason why this pattern doesn't work... The validator doesn't accept the format of the string I typed (i.e. 06201234567).
<input type="tel" pattern="06\d{7,9}" placeholder="06201234567">
I tried exactly the same code at w3schools' tryit editor, and there were no problem...
In HTML5 you can use <input type='tel'> and <input type='email'>
You can also specify a specific pattern like <input type='tel' pattern='[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}' title='Phone Number (Format: +99(99)9999-9999)'>
Something like pattern='^\+?\d{0,13}' Would give you an optional + and up to 13 digits
The form is in a template where I replaced some texts like {{example}} with other texts and php's preg_replace() search expression {{.*?}} matched {7,9} in the pattern and replaced it.
With the use of ({{.*?}}) everything's OK.

ng-pattern for not allowing input of a certain set of characters (e.g. +-!"¤%&/=?)

My question is exactly like my title. I'm writing a directive with an input field inside the template like below:
<input name="{{name}}"
id="{{name}}"
ng-model="message"
ng-maxlength="{{length}}"
maxlength="{{length}}"
type="text"
ng-pattern=" ... "
autocomplete="off"
/>
what should I fill in ng-pattern?
I finally use /[^0-9a-zA-ZøæåÆØÅöÖäÄüÜ\.\*\\,/\():\[\]= &-]/g
Thanks iismathwizard for mention the whitelist thing.
You can try this:
^[^+\-!"¤%&\/=?]+$
I'm not sure if you have more characters you need to disallow. Perhaps it would be easier to whitelist rather than blacklist "illegal" characters.
Regex101

HTML 5 Hex String for Pattern Attribute

I have several form elements that accept hex strings like the one shown below.
<input type="text" name="..." onkeyup="a('...')" pattern=\"[a-fA-F0-9]+\" value=\"****\"/>
I am interested in shorting the pattern attribute value to something shorter, but still accept the same pattern. I am doing this because this html is embedded in a micro controller and saving space is desirable. Is there a predefined cross browser hex matching class?
Only thing shorter is
<input pattern="[a-fA-F\d]+"/>
The \d character class is equivalent to 0-9.
More info: RegExp

Django Template linebreaks inside textarea tag

I have a variable with linebreaks, and am trying to insert it inside a textarea tag.
<textarea>{{ var_name }}</textarea>
I want the line breaks to be preserved so that it looks the same as when the variable is displayed
<div>{{ var_name|linebreaks }}</div>
Does anyone know how to do this?
Was able to solve this by replacing the \n to html code:
stringname.replace("\n", "&#10");
Within text area, \n appear as line breaks. As long as line breaks within your variable are encoded as \n, it should appear properly. If they are encoded differently, you can make your own custom template filter.
PS: Don't use linebreaks filter within text area because it replaces \n with html line break - <br>.

How do I deal with this regex issue?

I need to extract a value from a hidden HTML field, have somewhat figured it out but I'm currently stuck.
My regex looks like:
<input type="hidden" name="form_id" value=".*"
But this extracts the whole string from the HTML.
The string looks like:
<input type="hidden" name="form_id" value="123"/>
I need to extract the "value" from the string, it is always changing, but the "name" is always the same. Is there a way to extract it without doing another expression? I appreciate any help.
(?<=<[^<>]+?name="form_id"[^<>]+value=")(.*)(?=")
I just threw this together. Basically you want to negate any ending > in your request. So you'd likely want to do something of this nature:
<[^>]*hidden[^>]*value="(.*)"[^>]*>
And then read the first capture group (Delphi instructions). This keeps it as reasonably generic as possible although it does assume positional order on "hidden" and "value".
In order to find the value without regard for order you could use could use a slightly cleaner lookahead as was suggested:
^(?=.*name="form_id").*value="([^"]*)".*$
<[a-zA-Z"= _^>]*value="(\d*)"/>
I have tested this for your example.
If you want to extract for only input tag you can write:
<input[a-zA-Z"= _^>]*value="(\d*)"/>