Skip to main content
Inspiring
November 10, 2017
Question

How can you add text to a results driven text box?

  • November 10, 2017
  • 1 reply
  • 1234 views

Hi,

Is there anyway for a user to add text to a text box that has a custom script applied?

Joel_Geraci has given the following script which works perfectly, however I'm wondering if there's a way to do the same thing, only allow users to then add/change the text that's generated...any ideas?

Thanks

(My work around is simply put a separate text box at the side, but wondering if there's a script work around.)

var paras = [];

var fields = this.getField( “CB” ).getArray();

// sort by name

fields.sort( function( a, b ) {

var nameA = a.name.toUpperCase(); // ignore upper and lowercase

var nameB = b.name.toUpperCase(); // ignore upper and lowercase

if ( nameA < nameB ) {

return -1;

}

if ( nameA > nameB ) {

return 1;

}

     // names must be equal

return 0;

} );

for ( var i = 0; i < fields.length; i++ ) {

var field = fields[ i ];

if ( field.isBoxChecked( 0 ) ) {

paras.push( field.value )

}

}

event.value = paras.join( "\n\n " )

This topic has been closed for replies.

1 reply

Joel Geraci
Community Expert
Community Expert
November 10, 2017

Swap the last line with the following.

event.target.defaultValue = paras.join( "\n\n " );

this.resetForm([event.target.name]);

This will set the assembled string as the default value then clear that field so that the default is present but editable.

Inspiring
November 10, 2017

Hi Joel,

Such a speedy reply! Thank you

... I can't get that to work unfortunately - it still removes the inputted text.

Here's part of the file I'm working on if it helps? WeTransfer

Thanks again

Joel Geraci
Community Expert
Community Expert
November 10, 2017

Do you mean you want the checkboxes to append to some existing text or do you want it to replace any existing text but still allow for editing after the replace?