Page 1 of 1
Append text to a textbox
Posted: 20 Nov 2014
by Sonoma
I need to add text to a the end of a text box.
I need to add "lbs" directly after a text box to make it similiar to th "%" field.
I can easely append to the field but it gets seperated with a "<br />".
Since I need it the box and "lbs" on the same line I found a way to get around this too.
I am using this:
//Add lbs to end of field
$('.fd_field[fd_name="ALLB"]').find('br').remove();
fd.field('ALLB').control()._el().append("lbs<br />");
Is there anything more efficient or is this good enough?
Thanks.
Re: Append text to a textbox
Posted: 21 Nov 2014
by Dmitry Kozlov
Hi,
What type of the field do you use? If it's a single line of text field, you'd better use the following code:
Code: Select all
fd.field('ALLB').value(fd.field('ALLB').value() + 'lbs')
Re: Append text to a textbox
Posted: 21 Nov 2014
by Sonoma
That i a neat trick to put the LBS inside the text box. I will remember that. We have picky people.
This is a single line text box in the New and Edit forms. I needed to ad the LBS to the outside of the textbox and needed it on one line but the code always inserts a <br /> after the text box then adds the "LBS" to the end of the span like so:
<div ... fd_readonly="False"><span dir="none"><input placeholder="6of9" ... type="text">
<br> <----- Goal: Remove this and insert "LBS" the proper way
</span>
lbs
<br>
</div>
When I remove the <br> I get:
<div ... fd_readonly="False"><span dir="none">
<input placeholder="6of9" name="ctl00$ctl40$g_3228d2e9_0129_43fd_8287_724b9a830616$ALLBField$ctl00$ctl00$TextField" value="300" maxlength="5" id="ctl00_ctl40_g_3228d2e9_0129_43fd_8287_724b9a830616_ALLBField_ctl00_ctl00_TextField" title="ALLB" class="ms-long ms-spellcheck-true" type="text">
</span>
lbs <----LBS outside the span
<br>
</div>
The <br> before the </span> is gone. How could I make it look like this?
<input placeholder="6of9" name="ctl00$ctl40$g_3228d2e9_0129_43fd_8287_724b9a830616$ALLBField$ctl00$ctl00$TextField" value="300" maxlength="5" id="ctl00_ctl40_g_3228d2e9_0129_43fd_8287_724b9a830616_ALLBField_ctl00_ctl00_TextField" title="ALLB" class="ms-long ms-spellcheck-true" type="text">
lbs <----Goal: LBS inside the span
</span>
<br>
</div>
I feel that my way was a hack. I am still learning and getting there little by little. Every tweak I learn is allowing me to get to the point I can easily hand it off.
Thank you for this app. Works great. SharePoint should already have this feature.
Re: Append text to a textbox
Posted: 24 Nov 2014
by Dmitry Kozlov
Hi,
You can just put the field into a table and add 'LBS' text into a separate cell:

Re: Append text to a textbox
Posted: 17 Feb 2017
by Sonoma
If any one ever needs it.
1. Add text to Description field. e.g. lbs
2. In forms designer Add class to CSS Class. e.g. LBS
3. In jquery add the following: $('.LBS').find('br').remove();
4. Click OK, Save. Refresh.
LBS - Anything you like...