Fill textbox1 with content from textbox2, but if the content exceeds X length, only copy part of it

  • 26 January 2022
  • 1 reply
  • 7 views

Hello,

 

as the title suggests, im trying to copy the content of my textbox2 into textbox1, but if the length of the copied content exceeds 125 characters, only copy the first 125 characters and add "[...]" at the end.

To achieve this, I have a button, and two fields with Client-IDs (textbox1 and textbox2). This is in SharePoint 2013 on-premise inside a Nintex Form to create a new element in a list. 

I've got to the point where it copies the content of my textbox, but does not shorten/cut it. I feel like im really close, but im a total newb and just can't get it to work... hopefully one of you can help!

 

 

For the custom JS on the form i have this:

 

var autoFilltext = textbox2; 
function autoCopy () {  NWF$('#' + textbox1).val(NWF$('#' + autoFilltext).val());};

 

 

and for my button i have this onClick:

 

if (autoFilltext.length > 125) { autoFilltext = autoFilltext.substring(0, 124) + "[...]"; }; 
NWF$(document).ready(function(){    autoCopy();});

 

If you need anymore context, feel free to ask.


1 reply

Badge +8

hey @totalnewbie ,


 


i would create a formula and give it the varID textbox3:


 


IF(Length(textbox2) > 125, substring(textbox2, 0, 125) + "...", textbox2)


 


 



 


 


change ur JS accordingly:


 


function autoCopy () {  NWF$('#' + textbox1).val(NWF$('#' + textbox3).val());};

Reply