So what is this thing? No doubt, if you know me or work with me you've heard me talk about this tag. In a nutshell, I have taken the layout difficulties out of creating forms in your apps by combining Bootstrap's layout grid and every HTML5 form field into one tag. Combined with the power of CFML, this tag allows you to create input forms in a minutes rather than hours and update forms are as simple as copy and paste in most cases.
With the use of CFFORM discouraged - and yes, it should be avoided unless absolutely necessary - this custom tag is a great replacement. It does everything CFFORM does (did) and tons more.
Let's look at an example of the tag.
Every tag functions as a column (col-xl-*) in a Bootstrap grid. Each of these columns contains a y-axis margin of 2 (my-2) by default. In Bootstrap, within a grid row, you can actually have as many columns as you like and Bootstrap will rack and stack them within a row of the 12-column grid. So, using this tag, you can simply create a fluid container with one row and then add your fields...one after another. Organizing them is as simple as setting the size attribute to the desired column width (1-12). Here's a simple example:
If you wanted to take advantage of the grid to stack these fields, you could do it like so:
Which gives us this layout:
Generated by the tag
The name of the specified field. While the tag will name fields for you,
it is advisable that you specify your own name as the tag will generate
new names each time the form is loaded. While it is optional, it is recommended that you specify the name yourself. This will grant you control over the name of the field - which is required for data manipulation.
blank value
The default value of the field. The value is blank by default. Note: the value acts as a cfoutput tag. Simply feed in a ColdFusion variable name surrounded by ## and that will become the value of the field. Example: If you have a query named GetUser
that returns a column named email_address
, you would simply add #getUser.email_address# as the value of the field.
Generated by the tag
The ID of the specified field. While the tag will apply an ID for you, it is advisable that you specify your own ID as the tag will generate new names each time the form is loaded. Typically the NAME and ID of the field should match.
12
Defines the number of columns within the Bootstrap grid that the specified field will take up. Because the Bootstrap grid system uses a 12 column grid, values should be 1-12.
my-2
Controls the spacing of the fields using Bootstrap margins. It is recommended that you use the Y-axis margins and not all-around or X-axis margins.
text
Tells the tag which type of field to render. Any of these values are valid.
Field Label Here
Adds the label tag that should accompany each field requiring user input.
false
Allows you to hide the label, which acts as a block element. This is useful for stand-alone search fields or using a placeholder in place of the label. Hiding is done using the bootstrap d-none class.
Field Name Here
Adds a muted text description within a text-based field. Useful for showing users how to format the requested data.
false
Specifies whether or not a given field is required for the user to complete.
Please complete this field
Text that will appear should a user fail to complete a required field. Note: this attributes requires that you use Bootstrap form validation.
blank value
Text that will appear beneath the form field typically to detail instructions about the field's use.
*.*
Restricts the allowed file uploads when using type=
. Functioning strings are file_extension|audio/*|video/*|image/*|media_type. Example: file
type=
or *.pdf
type=
or image/*
type=
. You can also leave this attribute out and deal with the file upload using text/xml
<cffile action="upload">
.
false
Converts a textarea to the rich-text WYSIWYG editor, Summernote. Only used on
textarea type fields. Note: Requires calls to Sumemrnote CSS, JS, and other
files.
3
Sets the number of visible rows for a textarea.
1
Used for number type fields only. Sets the step between numbers in the number scroller.
0
Sets the minimum number in number type field scroller.
100
Sets the maximum number in number type field scroller.
stack
Used to set the flow of radio and checkbox fields to either stack or inline options.
1,2,3
A list of values that will appear as the value of radio, checkbox, and select boxes.
Item 1, Item 2, Item 3
A list of values that will appear as the visible item next to radios and checkboxes and select boxes.
mygroup
For fields of the type fieldgroup, this attribute names the group collectively.
3
Tells a FieldGroup how many fields to generate within the group.
3,3,4
For FieldGroup type fields, this is a comma separated list that depicts the number of characters to allow per field. For instance, the default of 3, 3, 4 is the basic pattern for a US phone number - therefore, allow three characters in the first field, three in the second, and four in the third.
number, number, number
blank
When using the type "chainedselect" this is the ID of the parent select box.
,
The delimiter for lists fed into radio, checkbox, and select boxes.
no
Sets the multiple select option on or off when using select boxes.
1
Sets the visible items in a multiple-select box.
Select One
Sets the text on the first select value in a required select field.
blank
Allows you to call a javascript function when a field is moved away from.
blank
Allows you to call a javascript function when a field is clicked on.
false
Sets the field to disabled. Disabled fields do not submit via GET or POST.
false
Sets the field to readonly. Use to submit fields via GET or POST operations.
blank value
Allows the inclusion of REGEX or other pattern for text fields.
false
For textline fields this will set the text to bold.
0
For textline fields allows you to specify the font size 1-4 which will set the HTML h1-h4 tags. Default of 0 will ignore this option.
no
Sets the Bootstrap btn-block class on submit, button, and reset fields.
false
Sets the Bootstrap text-center class on submit, button, and reset fields.
false
Sets the Bootstrap btn-lg class on submit, button, and reset fields.
false
Sets the size of a button element to small.
primary
Sets the Bootstrap bg-* class on submit, button, and reset fields. Valid inputs are primary, secondary, success, danger, info, warning, light, dark.
0
Sets the starting state of a switch type field. Valid input is 1 for on
and 0 for off
.
Off
Words that appear when a switch type field is set to the off
state.
On
Words that appear when a switch type field is set to the on
state.
On
Words that appear when a switch type field is loaded for the first time.
blank value
Use this to call javascript functions as the user types.
blank value
Use this to call javascript functions as the user types.
blank value
Allows you to run javascript commands when a select box selection changes.
blank value
Use this to restrict the length of input a user can enter into a textarea or text type field.
blank value
Allows you to specify a minimum length to a field.
blank
The values attribute is only used for FieldGroup type fields. This is a comma separated list of values. In most cases you will probably store the combined values from a FieldGroup as one value. It is advised that you split the values up - using a method similar to the one in the example, and then use them to create your list.
false
Use this when creating a button to convert it into a hyperlink button instead of a form button.
blank value
Use this when creating a linkbutton to specify the link for the button.
Boilerplate Text
This is the content of your modal window. Tip: You can use <cfsavecontent> to store complex info like forms and layout and then feed the variable into this attribute.
blank value
Use this to set the size of the modal dialog box. Possible options are sm, lg, and xl. The default size in Bootstrap is medium or md. Leaving this attribute off loads the default size.
blank value
Displays at the top of the modal window.
blank value
Provide the name of a Bootstrap color to change the color of the modal window header. Options are primary, danger, warning, info, secondary, success, dark.
true
Creates a button that will open your modal window when clicked.
blank value
Sets the data-toggle option for modal windows.
blank value
Sets the data-target option for modal windows.
blank value
Sets the data-dismiss option for modal windows.
false
Turns the tooltip on or off for a specific field. Note: If applying a
tooltip to a button, which you can do, make sure you set the proper
size and set block=true
.
Note: Tooltips require Fontawesome 5.x and the Bootstrap 4 tooltip script.
<link href="https://www.jackpoe.com/scripts/fa/css/all.min.css" rel="stylesheet">
OR
<link href="https://scripts.afit.edu/fontawesome/all.min.css" rel="stylesheet">
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
top
Tells the browser which direction the tip should open on. Possible are top, right, bottom, and left.
blank value
Provide the contents to appear within the tooltip.
false
Enables HTML content within the tooltipcontent attribute. Note: You will want to use single quotes within the attribute.
000000
Sets the default color of the tooltip bubble and arrow. Use HTML color notation without the #.
FFFFFF
Sets the default color of the tooltip text. Use HTML color notation without the #.
100%
Sets the width of the tooltip to allow wider content. This is particularly useful when inserting images into tooltips with HTML.
left
Sets the alignment of the text within the tooltip. Possible options are Left, Right, and Center.
1.0
Sets the opacity of the tooltip. By default the tooltips in Bootstrap are slightly transparent. This attribute allow you to override that behavior using standard CSS opacity decimals like 0.75 or 0.9. 1.0 is 100% opaque.
0.875rem
Allows you to override the default font size within the tooltip using CSS syntax. You can enter strings like 2.0rem or 12pt or even 15px.
6
Allows you to specify the length of the code to type. Mo more than 8 is recommended.
false
Allows you to choose whether or not the letters in the captcha will be all uppercase.
false
Allows you to choose whether or not the captcha will contain special characters.
false
Allows you to choose whether or not the captcha will contain numbers only.
"FFCC33"
Provide an HTML color code without the leading pound sign to set the color of the captcha image box.
666688
Provide an HTML color code without the leading pound sign to set the text color of the captcha code.
empty value
Name of the returned value containing the captcha code.
true
For better security the value of true should always be used. This passes the value of the captcha as an encrypted string.
empty value
Either a handmade string of characters (for CFMX_COMPAT) or a ColdFusion generated encryption key. Generate encryption keys for specific algorithms by using the generateSecretKey() function.
CFMX_COMPAT
The corresponding encryption algorithm for the provided key. Allowed values are AES,DES,DESEDE,RC2,RC4,RC5,BLOWFISH which require generated encryption keys and CFMX_COMPAT which requires a string of characters as a key. Note that CFMX_COMPAT is the least secure and, while it can be used for this kind of thing, it is recommended that you use one of the more secure algorithms. Secret keys for them can be generated using the generateSecretKey() function.
blank value
Allows you to pass extra Bootstrap classes into the class attribute of buttons.
Apples,Oranges,Bananas,Grapes,Peaches,Pears
A comma-separated list of items that will be suggested to the user as they type.
true
In order for the autocomplete to work, the list elements must be surrounded by double quotes. Setting this to true will take a list like Apples,Oranges,Bananas,Grapes,Peaches,Pears and turn it into "Apples","Oranges","Bananas","Grapes","Peaches","Pears"
theAutoCompleteItems
The name of the qualified list returned by the tag. This variable will contain the list you will feed into the simple jQuery script that makes the autocomplete function. TIP: You can see the returned variable by using the CFDUMP tag on the #variables# scope.
Creates a basic Bootstrap HTML button
<cf_jpBSfield size="2" name="test" id="test" type="button" value="Test Me" color="danger" onclick="alert('This works')" hidelabel="true">
Creates an Bootstrap-styled HTML submit button Note: If you hide the label on this field it will not line up with input fields if you are displaying it in the same line.
<cf_jpBSfield size="2" name="testSB" id="testSB" type="button" value="Submit Form" color="primary" hidelabel="true">
Creates a simple Bootstrap-styled HTML reset button.
<cf_jpBSfield size="2" name="testRB" id="testRB" type="reset" value="Reset Form" color="outline-secondary" hidelabel="true">
Creates a standard text input field.
<cf_jpBSfield size="12" ID="Foo" name="Foo" type="text" label="Your name" placeholder="" required="true" requiredtext="Please enter your name" value="">
Example of a text field with a tooltip enabled.
<cf_jpBSfield size="12" ID="Foo" name="Foo" type="text" label="Your Name" placeholder="enter your name" required="true" requiredtext="Please enter your name" value="" tooltip="yes" tooltiplocation="left" tooltipcontent="This is where you enter your name.">
Note: You also need to initialize tooltips with this script
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
Creates a standard HTML5 datepicker field. If you need to fill the value with a date by default, formatting needs to be done as yyyy-mm-dd.
<cf_jpBSfield size="12" ID="date" name="date" type="date" label="A date" placeholder="" required="true" requiredtext="Please enter a date" value="">
Creates a standard text field that validates email entry.
<cf_jpBSfield size="12" ID="email" name="email" type="email" label="e-mail address" placeholder="" required="true" requiredtext="Please enter a valid e-mail address" value="">
Creates a custom Bootstrap file field. Note: You will want to use the included script to make the field work correctly.
<cf_jpBSfield size="12" ID="MyFile" name="MyFile" type="file" label="Your document" placeholder="" required="false" requiredtext="Please upload a file" value="">
<script>
$('#MyFile').on('change',function(){
//get the file name
var fileName = $(this).val();
var cleanFileName = fileName.replace('C:\\fakepath\\', " ");
//replace the "Choose a file" label
$(this).next('.custom-file-label').html(cleanFileName);
})
</script>
Creates a standard hidden field. This field contains no Bootstrap column or label.
<cf_jpBSfield ID="hid" name="hid" type="hidden" value="ABCDEFG">
Creates a number field that includes a "spinner".
<cf_jpBSfield size="12" ID="yourage" name="yourage" type="number" label="Select Your Age" placeholder="" required="true" requiredtext="Please enter your age" value="" min="1" max="100" step="1">
Creates a standard password field. NOTE: You can use constraint validation in your FORM tag or other methods (using the onblur and onclick attributes) to check for password strength, requirements, and/or matches.
<cf_jpBSfield size="12" ID="Pass" name="Pass" type="password" label="Your Password" placeholder="" required="true" requiredtext="Please enter your password" value="">
Creates an HTML5 range slider
<cf_jpBSfield size="12" ID="yourage2" name="yourage2" type="range" label="Pick Your Age" placeholder="" required="true" requiredtext="Please pick your age" value="1" min="0" max="100" step="1">
Creates a Bootstrap toggle switch field. NOTE: Switches function like a checkbox and only exist if they are "on".
<cf_jpBSfield size="12" ID="News" name="News" type="switch" label="Would you like to receive our newsletter?" placeholder="" required="false" requiredtext="" value="" switchstate="0" onwords="Send me the newsletter" offwords="I do not want the newsletter">
Creates a standard tel field that validates telephone number entry. You can use the included script (or any script you like) to auto-format the phone number.
<cf_jpBSfield size="12" ID="TheTel" name="TheTel" type="tel" label="A telephone number" placeholder="999-999-9999" required="true" requiredtext="Please enter a telephone number" value="" onKeyup="autoformat()">
<script>
function autoformat(){
var inputValue = document.getElementById("TheTel").value;
var inputValueLength = inputValue.length;
if(inputValueLength == 3 || inputValueLength == 7){
document.getElementById("TheTel").value = inputValue+"-";
}
}
</script>
Creates a standard textarea field. Optionally, you can include a counter with the attached Bootstrap badge and jQuery script.
<cf_jpBSfield size="12" ID="Notes" name="Notes" type="textarea" label="Notes" placeholder="" required="true" requiredtext="Please enter your notes" value="" maxlength="200" rows="5">
<span class="badge badge-primary ml-3" id="count_message"></span>
<script>
var text_max = 200;
$('#count_message').html('0 / ' + text_max + ' Characters');
$('#Notes').keyup(function() {
var text_length = $('#Notes').val().length;
var text_remaining = text_max - text_length;
$('#count_message').html(text_length + ' / ' + text_max + ' Characters');
});
</script>
Creates a standard time entry field that validates time entry.
<cf_jpBSfield size="12" ID="time" name="time" type="time" label="A time" placeholder="" required="true" requiredtext="Please enter a time" value="">
Creates a standard URL field that validates URL entry.
<cf_jpBSfield size="12" ID="urla" name="urla" type="url" label="A url" placeholder="" required="true" requiredtext="Please enter a url" value="">
Creates an HTML5 color picker field. NOTE: The color picker may differ by browser and operating system.
<cf_jpBSfield size="2" ID="MyColor" name="MyColor" type="color" label="Your color" placeholder="enter your color" required="true" requiredtext="Please enter your name" value="##FFCC00">
Creates a standard checkbox or checkbox grouping. Use the included script to make sure at least one checkbox is selected.
<cf_jpBSfield size="6" ID="favs" name="favs" type="checkbox" listlabels="Beef,Cheese,Olives,Bread" listvalues="1,2,3,4" required="true" requiredtext="Please select your favorites" label="Select your favorites" flow="stack" value="2,3">
<script>
// sets the checkboxes in a group to required or not required on page load.
// change the value .favs to the name of your checkbox field
jQuery(function($) {
var requiredCheckboxes = $('.favs :checkbox[required]');
requiredCheckboxes.on('change', function(e) {
var checkboxGroup = requiredCheckboxes.filter('[name="' + $(this).attr('name') + '"]');
var isChecked = checkboxGroup.is(':checked');
checkboxGroup.prop('required', !isChecked);
});
requiredCheckboxes.trigger('change');
});
</script>
Creates a standard radio button or radio button grouping.
<cf_jpBSfield size="6" ID="favsCap" name="favsCap" type="radio" listlabels="Kirk,Picard,Sisko,Janeway,Archer" listvalues="1,2,3,4,5" required="true" requiredtext="Please select your favorite captain" label="Select your favorite captain" flow="stack" value="0">
Creates a standard select dropdown field. This example shows how to use a ColdFusion list to create the values. NOTE: If your list of items contains values that contain commas you will want to change the delimiter on them to something like a | character using listChangeDelims(). You can then add the attribute delim="|" to this tag and it will parse your lists properly.
<cfset shows = "The Original Series,Next Generation,Deep Space Nine, Voyager,Enterprise,Discovery,Picard,Lower Decks,Strange New Worlds">
<cfset abbrs = "TOS,TNG,DS9,VOY,ENT,DSC,PIC,LOW,SNW">
<cf_jpBSfield ID="BestSeries" name="BestSeries" size="6" label="Favorite Star Trek series" type="select" listlabels="#shows#" listvalues="#abbrs#" required="true" requiredtext="Please select your favorite series" value="TNG">
Creates a multiple select field. This example shows how to use a ColdFusion list to create the values.
<cfset shows = "The Original Series,Next Generation,Deep Space Nine, Voyager,Enterprise,Discovery,Picard,Lower Decks,Strange New Worlds">
<cfset abbrs = "TOS,TNG,DS9,VOY,ENT,DSC,PIC,LOW,SNW">
<cf_jpBSfield ID="BestSeries" multiple="1" listsize="#listLen(abbrs)#" name="BestSeries" size="6" label="Favorite Star Trek series" type="select" listlabels="#shows#" listvalues="#abbrs#" required="true" requiredtext="Please select your favorite series" value="TNG">
Inserts a line of text - not a form field. Useful for breaking up forms with instructions or other information. For information on the fontsize attribute, check the info in the attributes list above.
This is a simple line of text - not a field
<cf_jpBSfield size="12" ID="tl" name="tl" type="textline" value="This is a simple line of text - not a field" bold="true" fontsize="0">
Creates a standard search field with a clear button.
<cf_jpBSfield size="12" ID="k" name="k" type="search" label="" hidelabel="true" placeholder="Search for..." required="false" value="">
Creates a modal window with launch button. NOTE: You can turn off the button that launches the modal with the modalbutton attribute. You can then use data-toggle and data-target attributes in a hyperlink to open the modal or use jQuery to open it when the page loads. Note the inclusion of the "color" attribute. This is the color of the button that activates the modal. The button text can be specified using the "value" attribute.
<cfsavecontent variable="sampleContents">
Mr. and Mrs. Dursley, of number four, <a href="https://www.jackpoe.com">Privet Drive</a>, were proud to say that they were perfectly normal, thank you very much. They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense. Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache. Mrs. Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbors. The Dursleys had a small son called Dudley and in their opinion there was no finer boy anywhere. The Dursleys had everything they wanted, but they also had a secret, and their greatest fear was that somebody would discover it.
</cfsavecontent>
<cf_jpBSfield name="modalTest" id="modalTest" type="modal" value="Open Test Modal" color="danger" modalcontent="#sampleContents#" size="3" modalsize="lg" modalheadercolor="danger" modaltitle="Example modal" modalbutton="true">
Creates a searchable select box. NOTE: This field requires two additional files.
<cfset stchars = "Captain Kirk,Spock,Dr. McCoy,Scotty,Sulu,Chekov,Uhura,Picard,Riker,Data,Geordi,Worf,Wesley,Dr. Crusher">
<cf_jpBSfield ID="favoriteCharacter" name="favoriteCharacter" size="12" label="Favorite Character" type="searchselect" listlabels="#stchars#" listvalues="#stchars#" required="true" requiredtext="Please select your favorite character" value="" delim=",">
You may use...
<link href="https://scripts.afit.edu/css/searchSelect.css" rel="stylesheet" />
<script src="https://scripts.afit.edu/js/searchSelect.js"></script>
Or these...
<link href="https://www.jackpoe.com/scripts/css/searchSelect.css" rel="stylesheet" />
<script src="https://www.jackpoe.com/scripts/js/searchSelect.js"></script>
Initialize the field with this...
<script>
$('.select2').select2();
</script>
Creates a honeypot field that helps stop spam.
<cf_jpBSfield name="supervisor_name" id="supervisor_name" type="honeypot" value="" required="false">
<!--- Once the form has been submitted, check to see if the honeypot field has been filled in. If it has, the submission was done by a bot and the form should not be processed. If it is still empty then you know the user is real so process the form. --->
<cfif form.supervisor_name IS NOT ''>
<!--- This is a BOT. Do not process the form --->
<cfelse>
<!--- Place your code to process the form here --->
</cfif>
Inserts a captcha image and field to help keep forms from being resumbitted by spammers. Requires the companion tag jpBSCaptcha.
<cf_jpBSfield size="3" ID="ccode" name="ccode" type="recap" label="Enter this code below" requiredtext="Please enter the code" passlength="6" allcaps="yes" usespecial="no" boxcolor="f0f0f0" textcolor="666666" code="foo" key="@ThisIsMyKey" encrypt="true" algorithm="CFMX_COMPAT">
<!--- set cookies using the returned and encrypted code --->
<cfcookie name="captchaCookie" value="" expires="NOW">
<cfcookie name="captchaCookie" value="#foo#">
<!--- On your action page you will need to use the following companion tag --->
<cf_jpBSCaptcha cookie="captchaCookie" key="@ThisIsMyKey" algorithm="CFMX_COMPAT">
<cfif captchaStatus IS 1>
Do your stuff
<cfelse>
<cfoutput>#captchaError# #captchaErrorDetails#</cfoutput>
</cfif>
Using the tag requires a basic knowledge of Bootstrap 4, HTML forms, and ColdFusion. NOTE: Each field includes a
<form action="" method="post" novalidate class="needs-validation">
<div class="container">
<div class="row">
<cf_jpBSfield size="6" ID="fName" name="fName" type="text" label="Your first name" placeholder="enter your first name" required="true" requiredtext="Please enter your first name" value="" tooltip="true" tooltiplocation="top" tooltipcontent="Tooltip info here">
<cf_jpBSfield size="6" ID="lName" name="lName" type="text" label="Your last name" placeholder="enter your Last name" required="true" requiredtext="Please enter your last name" value="">
<cf_jpBSfield size="12" ID="address" name="address" type="text" label="Your address" placeholder="enter your address" required="true" requiredtext="Please enter your address" value="">
<cf_jpBSfield size="3" ID="City" name="City" type="text" label="Your city" placeholder="enter your city" required="true" requiredtext="Please enter your city" value="">
<cfset states = 'AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY'>
<cf_jpBSfield ID="state" name="state" size="2" label="Your state" type="select" listlabels="#states#" listvalues="#states#" required="true" requiredtext="Please select your state" value="">
<cf_jpBSfield size="2" ID="zip" name="zip" type="text" label="Your zipcode" placeholder="enter your zipcode" required="true" requiredtext="Please enter your zipcode" value="">
<cf_jpBSfield size="5" ID="email" name="email" type="email" label="Your e-mail address" placeholder="example:name@site.com" required="true" requiredtext="Please enter a valid e-mail address" value="">
<cf_jpBSfield size="6" ID="agree" name="agree" type="checkbox" listlabels="I agree!" listvalues="1" required="true" requiredtext="Please agree to the terms and conditions" label="I agree to the terms and conditions" flow="stack" value="">
<cf_jpBSfield name="sb" id="sb" type="submit" value="Submit Form" size="3" block="yes">
<cf_jpBSfield name="rs" id="rs" type="reset" value="Reset Form" size="3" block="yes">
</div>
</div>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
Allows you to create a series of selects that are chained together - also knows as cascading selects. Your first select box should just be a type="select". All child selects should be type="chainedselect". Using the attribute bsclasses, add the following class like so: bsclasses="select-relations". This CSS class is what tells the script which fields are chained. Your listvalues and listlabels should be formatted in a PARENT_VALUE:child value,PARENT_VALUE:child value,PARENT_VALUE:child value format.
<cfset data1 = "Chevrolet,Dodge">
<cfset data2 = "Chevrolet:Camaro,Chevrolet:Corvette,Dodge:Charger,Dodge:Challenger">
<cfset data3 = "Camaro:RS,Camaro:SS,Corvette:Stingray,Corvette:Z06,Charger:RT,Charger:Hellcat,Challenger:RT,Challenger:Hellcat">
<cf_jpBSfield ID="brandSelect" bsclasses="select-relations" name="brandSelect" size="6" label="Brand" type="select" listlabels="#data1#" listvalues="#data1#" required="true" requiredtext="Please select a brand" value="">
<cf_jpBSfield ID="modelSelect" name="modelSelect" bsclasses="select-relations" parentselect="brandSelect" size="6" label="Size" type="chainedselect" listlabels="#data2#" listvalues="#data2#" required="true" requiredtext="Please select a model" value="">
<cf_jpBSfield ID="selectTrim" name="selectTrim" bsclasses="select-relations" parentselect="modelSelect" size="6" label="Trim" type="chainedselect" listlabels="#data3#" listvalues="#data3#" required="true" requiredtext="Please select a size" value="">
<!--- Include the following below your jQuery call. --->
<script src="https://scripts.afit.edu/js/select-relations.min.js"></script>
<!--- OR --->
<script src="https://www.jackpoe.com/scripts/js/select-relations.min.js"></script>
Creates a series of fields in a Bootstrap Input Group. The fields will auto-advance (tab) when the specified length allowed for each field is reached. This is useful when asking for phone numbers, SSN, or other similar number groupings.
<!--- If you intend on using number fields you can apply this CSS to remove the --->
<style>
/* Chrome, Safari, Edge, Opera */
.fgrinputs::-webkit-outer-spin-button,
.fgrinputs::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Firefox */
.fgrinputs[type=number] {
-moz-appearance: textfield;
}
</style>
<!--- This illustrates a method to break up a phone number into the three fields --->
<cfset theValue = "9375551212">
<cfset v1 = left(theValue,3)>
<cfset v2 = mid(theValue,4,3)>
<cfset v3 = right(theValue,4)>
<cfset theValues = "#v1#,#v2#,#v3#">
<cf_jpBSfield size="6" fieldgroupname="cellPhone" type="fieldgroup" label="Your cell number" required="true" requiredtext="Please enter your numbers" values="#theValues#" fieldcount="3" fieldlengths="3,3,4" fieldtypes="number,number,number" placeholder="" helptext="Enter a phone number. The fields will automatically advance.">
<cf_jpBSfield size="6" fieldgroupname="cellPhoneAlt" type="fieldgroup" label="Your alt number" required="true" requiredtext="Please enter your numbers" values="" fieldcount="3" fieldlengths="3,3,4" fieldtypes="number,number,number" placeholder="" helptext="Enter a phone number. The fields will automatically advance.">
<!--- the auto-tab feature requires this script --->
<script>
$(document).ready(function(){
$(".fgrinputs").keyup(function () { //the tag automatically adds the fgrinputs class, which drives the feature
if (this.value.length == this.maxLength) {
var $next = $(this).next('.fgrinputs');
if ($next.length)
$(this).next('.fgrinputs').focus();
else
$(this).blur();
}
});
});
</script>
One of the newer input features on the web over the past few years is the autocomplete field - a field that suggests input as the user types. This kind of field can be useful when you want the user to be able to enter anything they need to enter, but suggest standard entries to help them type less.
<cfset StateList = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming">
<cf_jpBSfield size="12" ID="DreamState" name="DreamState" type="autocomplete" label="Which state would you like to live in most?" placeholder="Start typing the name of a US state..." required="true" requiredtext="Please enter your dream state" value="" autocompletelist="#StateList#" autocompletelistQualify="true" theAutoCompleteItems="TheItems">
<!--- You need to include this scripts --->
<script src="https://scripts.afit.edu/js/autocomplete.js"></script>
<!--- OR --->
<script src="https://jackpoe.com/scripts/js/autocomplete.js"></script>
<!--- include this script to activate the autocomplete.
Change the ID selector to the ID of your field.
Change the variable to the name specified in the theAutoCompleteItems attribute.
--->
<script>
$(document).ready(function()
{
var option_list = [<cfoutput>#theItems#</cfoutput>];
$("#DreamState").autocompleter(option_list, {});
});
</script>