gpwc-limit-line-breaks.js

Code

Filename: gpwc-limit-line-breaks.js

/**
 * Experimental Snippet 🧪
 */
// Limit the number of line breaks allowed in a GPWC field
var form_id     = 553; // Update this to the form ID
var field_id    = 1;   // Update this to the field ID
var lines_limit = 10;  // Update this to the maximum number of lines allowed
$( '#input_' + form_id + '_' + field_id ).on('keyup change input', function () {
	var lines = $( this ).val().split( /\r\n|\r|\n/ );
	while ( lines.length > lines_limit ) {
		var extraLine              = lines.pop();
		lines[ lines.length - 1 ] += extraLine;
	}
	$( this ).val( lines.join( '\n' ) );
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.