Passing multi word variable as default input to html textbox - html

I am passing a Python variable (x) storing a multi word value x="ABC DEF", to an html textbox as the default value. In the page, only the first word 'ABC' is displayed in the text box as the default value.
Here is the code snippet:
<td width="15%" bgcolor="WHITE" align="Left">
<input type="text" name=""",input_value,""" value=""",x,""" selected="selected">
</td>
How can I display the value 'ABC DEF' as default value in the text box?

I could suggest you the following bypass, since i'm no python expert, but it should work:
1. replace the space with some sign that there is no way you'll ever write on you own. for example: "!#R%33" (just an example yeah?. you can replace space with: "_" if it is ok with you).
capture that string you sent via php on server side and use str_replace from that sign to space again, and walla.. write the value inside the html.
Once again, that is a workaround. hope the idea would help.

Related

Model variable not showing initial space

Hi I have a model variable "name", which is binded to a span like
<input type="text" ng-model="name">
<span ng-bind="name"></span>
What my requirement is that to show up the text that are entered in the input field without eliminating any spaces.
I find a way to achive that by writing a css property
.allow-spaces{
white-space:pre;
}
so now if I enter a value "hello ooo buddy" it will show up exactly same in the span as well, but it will not show spaces at the begining like " hello buddy" is shown as "hello buddy". Please suggest me a solution for this.
ngModel by default trims beginning and trailing white spaces in input[type=text]. To disable this behavior write ng-trim=false in the input element.
Reference

How do I prevent BSP from adding a space to an integer variable?

Background
I'm making some changes to an existing custom BSP page in order to improve usability on Windows RT tablets.
I've been asked to change an input field (currently type="text") so that the number pad comes up when someone starts typing a value, in stead of the full keyboard. This is easily achieved by changing the input field type to type="number"
My Problem
After refreshing the page, (due to sorting, backing out from the next page etc). The integer field used as the value in the input field is coming back with an extra space attached to it:
My Code
data: lv_qty type i value 3.
<tr>
<td><%=lv_field1%></td>
<td><%=lv_fieldn%></td>
<td>|<%=lv_qty>|</td>
</tr>
Generated HTML:
<tr>
<td>Value1 </td>
<td>Value2 </td>
<td>
|3 | <!-- Note the extra space here! -->
</td>
</tr>
So I'm always getting the extra space; but it only causes a problem when trying to use it with <input type="number">
It is possible that BSP have not really been updated for HTML 5 and that I'm just stuck with this problem, but is there anything I can do on the server side to prevent this?
Client-side I'm considering using JavaScript to trim off the extra space, but it seems like an unnecessary workaround.
EDIT
Ok in trying to simplify the code for the question, I actually obfuscated the problem:
My real problem occurs when I'm trying to use lv_qty as an input field of type="number" and then refresh the page for whatever reason.
The code in this case is as follows:
data: lv_qty type i.
<tr>
<td><%=lv_field1%></td>
<td><%=lv_fieldn%></td>
<td>
<input type="number" value="<%=lv_qty%>">
</td>
</tr>
This is still simplified, but the problem becomes fairly obvious: (I put the value lv_qty in double-quotes).
I still think that the extra space that I get from the server side shouldn't be there, but the fix is pretty simple: Don't be an idiot and pass numbers back to the webpage as numbers, not strings :).
Try to use a string template with condense:
<td>|<%=|{ condense( lv_qty ) }|>|</td>
Remove the double-quotes around the integer value:
data: lv_qty type i.
<tr>
<td><%=lv_field1%></td>
<td><%=lv_fieldn%></td>
<td>
<input type="number" value=<%=lv_qty%> > <!--No double quotes here-->
</td>
</tr>
Since you are using a Z BSP, why not define lv_qty as a page attribute type string?
Then your display should be just the number.

Regex pattern not working properly

I'm working on a simple check for my input fields. I got 3 places where I'm validating user-input: javascript regex, html pattern and php regex. The Javascript and PHP part work fine, but my HTML pattern somehow returns an error for every input except blank. I tested it on regexpal.com (regex tester) and it works perfectly fine there, so I reckon I must be doing something wrong.
Here's my regex:
/^[a-zA-Z0-9\!\?\,\.\s]{0,50}$/
I'm trying to allow users to input the following:
Alphabetic characters, including capitals
Numeric characters
Puncation: exclamation(!), question(?), comma(,) and dot(.)
Spaces
Here's how I implement it:
<input type="text" id="name" name="name" aria-required="true" pattern="/^[a-zA-Z0-9\!\?\,\.\s]{0,50}$/" value="loaded value from db">
Please note: I'm allowing 0 characters to be entered because I will check it with PHP, and if the input field(s) is/are empty, a pre-set value will be written to the database.
Basically it should allow users to enter general words or sentences, but somehow it doesn't allow anything. The only way I don't get an "error" is when I leave the inputfield blank. What am I doing wrong? Is my regex wrong? Am I not implementing it correctly? I can provide more code if necessary.
Help is much appreciated!
Thanks in advance.
Try removing the forward slashes (/) from the input's pattern attribute.

HTML - Lock default value in text area and user insert more info

Im not sure on how to explain this but, what I want to know is there if there is any way to "lock" just one part of an text area in a html form. Example:
<input name="example" type="text" id="example" valeu="__this part cant be modified__, and here user insert aditional info" />
And then I get this field value as like: "this part cant be modified + what user typed"
Thank you
I don't think you can, your best bet would probably to just append your default value to their input upon submission.
No, there isn’t, not for input elements, not for textarea elements.
You can however create an impression of such behavior, e.g. having some text and an input element on the same line and setting their style as similar as possible (setting all text, background, and border properties). Of course, the form data would still consist of the input value. And prepending the fixed text to it in client-side JavaScript would be possible but normally pointless, since it would be inherently unreliable and since you can simply make the form handler behave as if it got that string (i.e., make it have it as built-in data).

How to preserve text transform formatting applied to input box?

I am applying some formatting to input made inside a text box in a web page.
<input style="text-transform: uppercase"
type="text"
class="textbox"
id="code"
name="code"
D_LABEL="code"
beanProperty="code"
value=""
D_MANDATORY="true"
maxlength="10"/>
This works fine. I am saving the value in a database. However the value saved is not in upper case. How do save the same value as it appears on the text box at the time of capture?
It will not be uppercase, the text is lowercase, or case-dependent on how it is entered, CSS simply manipulates the visual layer, not the data.
The above answers point you in the right direction . You can simply convert the input box text to uppercase in javascript before sending the data to server. Use <string>.toUpperCase() method to achieve the conversion
There is no way to guarantee this on the client side. You need to perform string manipulation on the server side.
PHP Example:
$input = $_POST["code"];
$val = strtoupper($input);
There is a difference between 'value' and 'presentation'. The value stays as it was – it is only presented by CSS in uppercase. If you need an uppercase value, you'll need to transform it after transferring to the server.