Append text to a textbox

rss

Posted by Sonoma - Nov 20 ’14 at 03:30

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.

 

 

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 5 years 10 months 26 days
    #1 by Dmitry Kozlov Nov 21 ’14 at 03:23

    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:

    fd.field('ALLB').value(fd.field('ALLB').value() + 'lbs')
    
  • Sonoma
    Member
    Member for: 4 years 10 months 22 days
    #2 by Sonoma Nov 21 ’14 at 09:49

    [#1]: 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.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 5 years 10 months 26 days
    #3 by Dmitry Kozlov Nov 24 ’14 at 05:29

    [#2]: Hi,

    You can just put the field into a table and add 'LBS' text into a separate cell:

    Add a note to a field in SharePoint form

  • Sonoma
    Member
    Member for: 4 years 10 months 22 days
    #4 by Sonoma Feb 17 ’17 at 05:26

    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...

Displaying 1 to 4 of 4 messages