You are viewing limited content. For full access, please sign in.

Question

Question

Setting height and width for a text box

asked on March 30, 2018

I have been trying to work with a customer to create a JavaScript function in order to manipulate the amount of characters for a text box. The current issue that we are experiencing is that when starting from the first line when entering a certain amount of characters the second line is deleted. This only happens if edits are being made on a previous line. What we would like it to do is to pop the characters at the end instead or prevent adding characters after a given limit lets say 16x6. I have attempted to make edits on my own and to rewrite the code that was obtained from stackoverflow. Has anyone been able to accomplish this?

$(document).ready(function() {
var textarea = document.getElementById("Field192");
//textarea.onkeyup = function() {
$('.maxlinescharComments textarea').on('input focus keydown keyup', function() {

var lines = textarea.value.split("\n");

var start = textarea.selectionStart;

var end = textarea.selectionEnd;

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

if (lines[i].length <= 16) continue;

var j = 0; space = 16;

while (j++ <= 16) {

if (lines[i].charAt(j) === " ") space = j;

}

lines[i + 1] = lines[i].substring(space + 1) + (lines[i + 1] ? " " + lines[i + 1] : "");

lines[i] = lines[i].substring(0, space);

}

textarea.value = lines.slice(0, 6).join("\n");

if (start == end) {

textarea.setSelectionRange(start, end);

}
});
});

The reason for the height and the width is that the text will be imported into a PDF after the form has been submitted and we would like to ensure that the text that was input fits in the text box. 

0 0

Replies

replied on March 30, 2018

Is there some reason you can't use the built in character limit for the field?

0 0
replied on April 13, 2018

The reason why is that users are able to put in new line characters and the PDF that the data is being inserted into has limited space.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.