Input Form Group Component
Overview
Here is an overview of the Input_form_group class:
class Input_form_group {
constructor (opts = false) { ... }
get_class_defaults () { ... }
get_generate_options (options) { ... }
generate (options = false) { ... }
}
Default Settings
The following object properties and values are all of the defaults for this class:
{
aria_describedby_suffix : '-help',
classes : {
clear_text_buttons : 'btn btn-lg position-relative opacity-50 p-2 border-0 bg-transparent',
clear_text_parents : 'position-relative text-right',
form_error_texts : 'd-none form-text text-danger',
form_groups : 'form-group mb-4',
form_help_texts : 'form-text text-muted',
form_success_texts : 'd-none form-text text-success',
form_text_parents : 'text-left pr-2',
form_text_wrappers : 'd-flex justify-content-between align-items-start',
inputs : 'form-control form-control-lg',
label_buttons : 'btn btn-sm btn-link pb-1 pl-3 pr-0',
label_button_icons : 'fas fa-question-circle text-primary',
label_wrappers : 'd-flex justify-content-between align-items-center',
labels : 'mb-1'
},
clear_text_button_styles : 'top:-48px; -webkit-appearance:none;',
clear_text_button_text : '×',
error_text_suffix : '-error',
form_modal_text : {
heading: 'Form Inputs',
body: [{
type: 'paragraphs',
content: [ 'Form Inputs are very useful and convenient options to help users enter data. Inputs allow a user to type in data for a single line, that expands horizontally if a user types a lot of content.' ]
}]
},
form_text : {
help : ['Default Input help text'],
error : ['Default Input error text'],
success : ['Default Input success text']
},
id : 'default-input-id',
label : 'Default Input Label',
name : 'default-input-name',
placeholder : 'Default Placeholder',
success_text_suffix : '-success',
type : 'text',
value : '',
required : false
}
Methods
The following class methods allow you to interact with the Input_form_group class object.
constructor(opts)
Class constructor with an optional argument expecting an object with class-specific properties/values. Any matching properties passed will override the default values. The constructor function exposes a .defaults object containing various default settings for the component.
<script type="module">
// import module
import { Input_form_group } from './js/modules/form_components.js';
// create an object with your overrides specified
let input_default_settings = {
id : 'first-name',
label : 'First Name:',
name : 'first-name',
placeholder : 'Enter a Name',
required : true
};
// initialize the class and pass your settings as an argument
let inputs = new Input_form_group(input_default_settings);
// confirm your changes
console.log( inputs.defaults.attributes.class );
</script>
get_class_defaults()
Returns an object with all of the default properties of the Input_form_group class.
<script type="module">
// import module
import { Input_form_group } from './js/modules/form_components.js';
// initialize the class and call the method
console.log( new Input_form_group().get_class_defaults() );
</script>
Conversely, you can also access the Class defaults directly after initializing the class, and without the get_class_defaults() method:
<script type="module">
// import module
import { Input_form_group } from './js/modules/form_components.js';
// initialize the class and call the method
console.log( new Input_form_group().defaults );
</script>
get_generate_options()
Requires an object to be passed as an argument. The argument will override the default settings of the class, but ONLY in the scope of this method. This method is mainly provided for debugging purposes.
<script type="module">
// import module
import { Input_form_group } from './js/modules/form_components.js';
// initialize the class and pass your settings as an argument
let inputs = new Input_form_group();
let my_test_settings = {
id : 'first-name',
label : 'First Name:',
name : 'first-name',
placeholder : 'Enter a Name',
required : true
};
// initialize the class and call the method
console.log( inputs.get_generate_options( my_test_settings ) );
</script>
generate()
Takes an optional argument expecting an object with class-specific properties/values. Any matching properties passed will override the default values. This method returns a node list of DOM element(s), configured according to the class defaults and any overridden settings.
<script type="module">
// import module
import { Input_form_group } from './js/modules/form_components.js';
// initialize the class and pass your settings as an argument
let inputs = new Input_form_group();
// set your desired settings for the component elements you're about to generate
let input_settings = {
id : 'first-name',
label : 'First Name:',
name : 'first-name',
placeholder : 'Enter a Name',
required : true
};
// generate the component nodes to spec by passing your settings in
let input = inputs.generate( input_settings );
</script>