JavaScript Docxpresso helpers

The JavaScript Docxpresso helpers are a set of JavaScript functions that are by default loaded in the document/web form interfaces that have the ultimate goal to simplify the life of developers integrating methods that have shown useful in the past.

Due to its very own feature this collection of helper functions is expected to grow in the future incorporating new user needs as they pop up so, please, let us know if there is any JavaScript method or utility that you may feel is of general interest so it may be included.

By the time being the available methods include:

limitCharNumber(myvar, limit)

This method allows to limit the number of chars that may be introduce in a Docxpresso text or rich text variable.

The parameter myvar stands for the name of the corresponding Docxpresso variable while limit is an integer with the requested maximum number of characters.

For example limitCharNumber(‘name’, 30) will not allow the end user to introduce more than 30 chars in the corresponding “description” variable.

Notice that this is different from a custom validation that will inform to the end user, or even block the submission of the document, that a certain text is longer than expected. limitCharNumber will block the introduction of new characters whenever the limit is hit.

cloneGroupIdElement(id, ntimes, type, match)

This helper method is designed to greatly simplify the task of cloning blocks (table rows, list items or bookmarked content) via JavaScript.

This method allows for the automatic fulfilling of document data when the replication of blocks is a must and the data does not proceed directly from Docxpresso databases (in that case all the data required for the cloning of blocks is already embedded in the corresponding JSON object).

The meaning of the different parameters is:

  • id: this is the internal Docxpresso id of the block that we wish to clone and we will explain below how to obtain it.
  • ntimes: the number of times that we want to replicate the corresponding block.
  • type: it can be row, list or bookmark
  • match: in case a particular block appears more than once the occurrence/match that should be cloned.

In order to get the required id the simplest way is to use a browser inspector and look for the first parent element of the block that we wish to clone with the data-id attribute.

For example in the case of this table row:

template versions

One may also generate this token programmatically by generating the md5 hash of all the variables contained in that block element, i.e. if the table row contains two variables like product and Price.

The data-id can be generated by:

	data-id = md5(‘product,Price’);

launchWarning(title, message)

This method allows to throw a simple warning message Docxpresso style (Docxpresso uses internally the toastr jQuery plugin).

Its use is obvious. For example, launchWarning (“Beware”, “This is the message.”) will generate the following warning:

template versions

launchMessage (title, message)

This method is very similar to the previous one and allows to launch a pop up message Docxpresso style where you can include HTML.

Its use is again obvious. For example, launchMessage (“My Message”, “This is the message.”) will generate the following pop up:

template versions

launchConfirmSend (title, message, type)

This method is mainly thought to work together with the confirmOnSubmit event so one may ask the user for further confirmation before sending the data to the Docxpresso server instance.

The usage is very similar to launchmessage allowing to launch a pop up confirm message Docxpresso style where you can include HTML in the message variable.

The type variable may be left blank (the most standard use case) but it may also forced to take the value “continueLater” that can be used to force confirmation programmatically in the case that the template admits to continue edition later.

Its use is again obvious. For example, launchConfirmSend(‘My Confirmation’, ‘This is the message.’) will generate the following pop up:

template versions