Skip to content

Instantly share code, notes, and snippets.

@lesutton
lesutton / MonthDropDownFromSelectedDate.js
Created February 11, 2021 22:37
Create an Adaptive Form Dropdown List that displays a list of month starting from the selecting month but displaying remaining months in a loop.
var theArray = [];
try{
var theDate = moment(datepicker1613080063009.value);
var theMonth = theDate.format('M');
var theMonthInt = parseInt(theMonth);
@lesutton
lesutton / TextField_Validate.js
Created January 15, 2021 15:59
Allow only alphanumeric input into an Adaptive Form text field.
alphanumeric(this.value);
function alphanumeric(inputtxt) {
var letterNumber = /^[0-9a-zA-Z]+$/;
if(inputtxt.match(letterNumber)) {
return true;
} else {
return false;
}
}
@lesutton
lesutton / noSpecialCharactersInField.js
Created December 23, 2020 19:13
No special characters in Adaptive Forms Field.
var theValue = this.value;
var theRegex = /[^a-zA-Z0-9 \#\@\$\!\+//]/;
if(theValue){
if(!theRegex.test(theValue)){
true;
} else {
false;
}
} else {
true;
@lesutton
lesutton / getThatCookie.js
Created December 23, 2020 18:05
Get Cookie Inside Adaptive Form
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
@lesutton
lesutton / AdaptiveFormValidDate.js
Created December 23, 2020 01:58
Adaptive Form Date - On Validate YYYY/MM/DD for Valid Layout and Date
isValidDate(this.value);
function isValidDate(dateString) {
var regEx = /^[0-9]{4}(\/){1}[0-9]{2}(\/){1}[0-9]{2}/;
if(dateString.match(regEx)){
var d = new Date(dateString);
var dNum = d.getTime();
if(!dNum && dNum !== 0){
@lesutton
lesutton / adaptive_form_mandatory_indicator.css
Created December 10, 2020 20:01
Add a mandatory "star" indicator to the end of all the field labels of an adaptive form.
div[data-mandatory*="true"] .guideFieldLabel label::after {
content: "*";
color: red;
}
@lesutton
lesutton / sorted_country_list.json
Last active May 4, 2022 15:55
sorted_country_list.json
[
"AD=Andorra",
"AE=United Arab Emirates",
"AF=Afghanistan",
"AG=Antigua and Barbuda",
"AI=Anguilla",
"AL=Albania",
"AM=Armenia",
"AO=Angola",
"AQ=Antarctica",
@lesutton
lesutton / cards.html
Created October 22, 2020 12:49
Sample of HTL Implementation of the row of cards demonstrated in the SB Admin 2 template.
<sly data-sly-template.card="${ @ title, style, value}">
<div class="col-xl-3 col-md-6 mb-4">
<div class="card border-left-success shadow h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold ${style} text-uppercase mb-1">${title}</div>
<div class="h5 mb-0 font-weight-bold text-gray-800">${value}</div>
</div>
<div class="col-auto">
@lesutton
lesutton / lineCounter.js
Last active October 7, 2020 23:26
Show line number in a repeating panel in an adaptive form.
var currentInstanceNumber = this.parent.parent.instanceIndex + 1;
this.value = "Line Number " + currentInstanceNumber;
/* The repeating panel in this case is 2 levels above. The field is inside a panel, that is inside another panel. */
@lesutton
lesutton / ValidateFileNameBeforeSubmitting.js
Created October 6, 2020 20:57
Validate File Name before submitting an Adaptive Form
var component = attachmentA; // Field whose value has changed
var fileItems = $('#'+component.parent.id).find(".guide-fu-fileItem");
for (i = 0;i<fileItems.length;i++) {
var filename = $(fileItems[i]).find(".guide-fu-fileName").text();
//check whether it is previously attached file or a newly attached one
console.log("filename: "+ filename);
if(filename!="helloworld.pdf"){
alert("You must correct your file name before submitting");