Changes

Jump to: navigation, search

JavaScript Validation

2,704 bytes added, 14:52, 9 July 2021
To limit the amount of characters that can be entered into a field
{| class="wikitable"
|-
|[[Image:How.png|50px|link=]]
|This article will explain '''how''' you can implement this feature for use on your SmartSimple system.
|}
 
{{JavaScript Syntax}}
__TOC__
The JavaScript syntax can be entered into the ''JavaScript Validation'' field on the custom field settings page.
 
If '''SmartCheck''' is enabled, every reference to "frm.cf_''fieldid''.value" should be changed to;
form.getStr("cf_fieldid")
==To accept only certain values==
>100 or @value@>100 in the Custom box.
 
==To limit a date to the future==
 
ConvertDateStr(@value@,"@dateformat@")>''date''
 
'''Where'''
 
''date'' is a date in the format "YYYY-MM-DD"
 
'''Example'''
 
To limit the date to a future date greater than today
 
ConvertDateStr(@value@,"@dateformat@")>"@YEAR(currentdate)@-@MONTH(currentdate)@-@DAY(currentdate)@"
==To limit the amount of characters that can be entered into a field==
 
@value@.length<''n''
@value@.length<35
 
==To validate the length of a number entered into a field==
@value@.toString().length==n
 
'''Where'''
 
''n'' is any number
 
'''Example'''
 
To see if the length of a number is 10
 
@value@.toString().length==10
==To have a custom field only accept values in a range==
==To perform pattern matching==
isMatch(@value@, ''pattern'', ''isEmptyOK'')
Where ''pattern'' is
To validate 9 digits SIN number, put this into the box
isMatch(@value@, 'NNNNNNNNN', false)
==To allow only numbers and one other character==
parseInt(@value@)==@value@
 
==To restrict a special character or a string==
 
@value@.indexOf("enteryourstringhere")==-1
==To check if a phone number of a certain format==
frm.cf_@Project Budget.id@.value>=@value@
 
If SmartCheck is enabled, use the following instead;
form.getStr("cf_@Project Budget.id@") >= @ value@
You can perform validation against standard fields as well. For example, to validate that the a Canadian postal code syntax should only be enforced for Canadian contacts, use:
document.frmuser.ucountry.value!="10" || isMatch(@value@, 'LNL NLN', true)
The syntax is:
If you wish to make a field mandatory ''only if'' the value ''Yes'' is selected from a dropdown field, for example, use:
@value@!=="" || frm.cf_''fieldid''.value!="Yes"
in the JavaScript validation setting where:
* ''fieldid'' is the [[Custom Field ID|custom field ID]] of the dropdown field
 
When using this method, ensure that "Allow Empty" is selected for this field.
 
==To make a [[Check Boxes]] field conditionally mandatory==
 
If there is a check box field under a [[showhideheader]] and you wish to make this check box field mandatory ''only if'' the value '''Yes''' is selected from a [[Combo Box]] field, use the JavaScript below in the [[JavaScript Validation]] on the [[Check Boxes]] custom field:<br />
 
'''isChkSelected(frm.cf_''fieldid'') || frm.cf_''fieldid''.value!="Yes"'''
 
 
In the JavaScript validation syntax where<br />
:1) '''isChkSelected(frm.cf_''fieldid'')''': this (frm.cf_''fieldid'') is the field id of the check box field to be made conditionally mandatory.<br />
:2) '''frm.cf_''fieldid''.value''': this (frm.cf_''fieldid'') is the [[Custom Field ID|custom field ID]] of the [[Combo Box]] field that controls the visibility of the Check Boxes field.<br />
 
For example:
* A combo box field: Did your organization receive any financial assistance? (custom field id 545454)
: * Options are Yes;No;
 
If yes is selected than they should answer a mandatory check box field. '''Which of the following types of financial assistance''' (custom field id 989898).
 
Include the following JavaScript Validation on the check box field:
isChkSelected(frm.cf_989898) || frm.cf_545454.value!="Yes"
 
When using this method, ensure that "Allow Empty" is selected for this field.
==See Also==
* [[savefunc]]
* [[Email validation isEmail / isEmail2]]
* [[Maximum Length]]
 
{| class="wikitable"
|-
|[[Image:Why.jpeg|50px|link=]]
|Click [http://wiki.smartsimple.com/wiki/Updated_Functionality_for_Maximum_Word/_Character_Limit_-_Why%3F here] to learn why this feature is a benefit to your organization.
|}
[[Category:Custom Fields]][[Category:JavaScript]][[Category:Validation]][[Category:How]]
2
edits

Navigation menu