Skip to main content

Trying to limit the size of a field. 

View from the debugger.

201987_pastedImage_1.png

Code Source:

https://community.nintex.com/community/build-your-own/blog/2014/12/08/nintex-forms-how-to-limit-maximum-length-of-input-field-during-typing

NWF$(document).ready(function(){
NWF$("body").append('<div id="charCounter";></div>'); // create div for counter
var zaehlerFeld = NWF$('#charCounter'); // save as jquery object
zaehlerFeld.hide(); // hide the div
NWF$(""class*=kob-maxtextlen-]").each(function () { // for all html elemts with class name beginning with kob-maxtext-len
var classes = this.className.split(" "); // splitt class names
for (var i = 0; i < classes.length; i++) { // for all class names of the actual html
if (classes.substr(0, 15) == "kob-maxtextlen-") { // check if class name begins with kob-maxtext-len
var maxlen = parseInt(classes.split('kob-maxtextlen-'))1]); // extract the number at the end of the class name
NWF$(this).on('focus input blur', function () { // define an event function
zaehlerFeld.show(); // show counter
zaehlerFeld.css({ // format counter
"text-align":"center",
"display":"inline-block",
"background-color":"#FFF",
"border":"1px solid",
"box-shadow":"3px 3px 3px #888",
"height":"16px",
"width":"22px"
});
MaxTextLaenge(NWF$(this), maxlen, zaehlerFeld); / call check function
});
NWF$(this).blur(function () {
zaehlerFeld.text(' ');
zaehlerFeld.hide();
});
}
}
});
});

function MaxTextLaenge(textFeld, maxAnzahl, zaehlerFeld) {
zaehlerFeld.position({ // positioning the counter
my: "left top-16",
at: "left top",
of: textFeld,
collision: "fit"
});
if (textFeld.val().length > maxAnzahl) { // more then max characters enterd
textFeld.val(textFeld.val().substr(0, maxAnzahl)); // limit to max text length
textFeld.css('border-color', 'red'); // show control border in red
zaehlerFeld.text(0); // no more input allowed
} else {
zaehlerFeld.text(maxAnzahl - textFeld.val().length); // count down counter
textFeld.css('border-color', ""); // normal border
}
}

Hi there:

This may not be super helpful, I am unsure, but this guy here:

 

Found it was coming from INSIDE THE HOUSE ... .. er, I mean, the filler.min.js file.


There was no resolution on the issues posted, but perhaps now in 2017 we can figure out how to get to the bottom of it.

Good luck,

Rhia


you have syntax error on the following line, this may cause unexpected errors

MaxTextLaenge(NWF$(this), maxlen, zaehlerFeld); / call check function

Since I didn't write the line and it has three parameters, do you have any idea what's wrong?


I saw that too--just don't know what to do with it.


The comments not right. I'll try it again:

MaxTextLaenge(NWF$(this), maxlen, zaehlerFeld); // call check function

yes, exactly. I thought you'll spot it immediatelly happy.png


I got it working--but it doesn't seem to be as robust as I'd like. Works ok for new entry ok. Turns the text outline red--but doesn't do anything with validation.

When you enter a change the indicator box no longer reflects the character count.

For right now just going to limit the text box--it is a no hassle move. Not Elegant but works.

Since I haven't played much with the forms and JavaScript, it's nice to know the error was just a one-off not my whole installation. 

thanks,

Stephan


Reply