Replace text/wildcards in captions, buttons, table headers and more
You can use [wildcards] in a lot of places on your form and they get automatically parsed and updated. However, if you need to use wildcards in a fields caption, a button label or a table heading row for example, wildcards are not support there.
We've come up with this small JS action you can attach to your form that will find and replace specific values using a value (wildcard) pulled from another field
1. Attach this script to the forms root node > actions.
// use value in the 'year' field to do replace. This can also be static value var newvalue = form.getFieldByName('year').getValue(), // this is the value we are replacing (hard coded in field captions, and table headers // buton labels etc replace = '2017'; // get current page element var page = $('.formContainer'); // get elements that may contain text var elements = $('.lf_page_open_subhead,.lf_page_open_head,label,.alert,.head,.subhead,.btn,.tab_text')
// loop over and run find and replace elements.each(function(i){ var el = $(this); var newstring = u.replaceAll(el.text(),replace,newvalue); el.text(newstring) })
The same code is repeated below, but this time setup to listen to the forms page change event, so that it runs on each page of a multi page form as it is loaded.
1. Attach this script to the forms root node > actions.
// This function will receive the field and form objects. function(field,form){ var replacetextOnPageLoad = function(mp,newpage,oldpage){ // use value in 'year' field to do replace var newvalue = form.getFieldByName('year').getValue(), // this is the value we are replacing (hard coded in field captions, and table headers // buton labels etc replace = '2017'; // get current page element var page = $('#page_'+newpage.id); // get elements that may contain text var elements = $('.lf_page_open_subhead,.lf_page_open_head,label,.alert,.head,.subhead,.btn,.tab_text')
// loop over and run find and replace elements.each(function(i){ var el = $(this); var newstring = u.replaceAll(el.text(),replace,newvalue); el.text(newstring) }) } // do this on each page change event form.mp.eventMgr.addListener('pagechange',replacetextOnPageLoad); // call it manually for the first page (no page change event is generated) replacetextOnPageLoad(form.mp,form.mp.getCurPage()) }
0 Comments