MOLECULAR COMPONENTS

Input Character Counter Form Group Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Input_character_counter_form_group class:

    
        class Input_character_counter_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',
                                        characters_count_suffix : '-characters',
                                        classes : {
                                            form_groups               : 'form-group mb-4',
                                            label_wrappers            : 'd-flex justify-content-between align-items-center',
                                            labels                    : 'mb-1',
                                            label_buttons             : 'btn btn-sm btn-link pb-1 pl-3 pr-0',
                                            label_button_icons        : 'fas fa-question-circle text-primary',
                                            inputs                    : 'form-control form-control-lg',
                                            clear_text_parents        : 'position-relative text-right',
                                            clear_text_buttons        : 'btn btn-lg position-relative opacity-50 p-2 border-0 bg-transparent',
                                            form_text_wrappers        : 'd-flex justify-content-between align-items-start',
                                            form_text_parents         : 'text-left pr-2',
                                            form_help_texts           : 'form-text text-muted',
                                            form_error_texts          : 'd-none form-text text-danger',
                                            form_success_texts        : 'd-none form-text text-success',
                                            character_counter_parents : 'small text-right text-muted form-text'

                                        },
                                        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    : 'char-input-id',
                                        label : 'Character Counter Input',
                                        masking : {
                                            enable: false,
                                            type: 'phone',
                                            min: 0,
                                            max: 1000,
                                            seperator: ','
                                        },
                                        max_characters      : '50',
                                        name                : 'char-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_character_counter_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_character_counter_form_group } from './js/modules/form_components.js';

                                        // create an object with your overrides specified
                                        let counter_input_default_settings = {
                                            id             : 'username',
                                            label          : 'Create Your Username:',
                                            name           : 'username',
                                            placeholder    : 'Enter a username',
                                            max_characters : 30,
                                            required       : true
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let counter_inputs = new Input_character_counter_form_group(counter_input_default_settings);

                                        // confirm your changes
                                        console.log( counter_inputs.defaults.attributes.class );

                                    </script>
                                
                            

get_class_defaults()

Returns an object with all of the default properties of the Input_character_counter_form_group class.

    
        <script type="module">
        
            // import module
            import { Input_character_counter_form_group } from './js/modules/form_components.js';

            // initialize the class and call the method
            console.log( new Input_character_counter_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_character_counter_form_group } from './js/modules/form_components.js';

            // initialize the class and call the method
            console.log( new Input_character_counter_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_character_counter_form_group } from './js/modules/form_components.js';

                                        // initialize the class and pass your settings as an argument
                                        let counter_inputs = new Input_character_counter_form_group();

                                        let my_test_settings = {
                                            id             : 'username',
                                            label          : 'Create Your Username:',
                                            name           : 'username',
                                            placeholder    : 'Enter a username',
                                            max_characters : 30,
                                            required       : true
                                        };

                                        // initialize the class and call the method
                                        console.log( counter_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_character_counter_form_group } from './js/modules/form_components.js';

                                        // initialize the class and pass your settings as an argument
                                        let counter_inputs = new Input_character_counter_form_group();

                                        // set your desired settings for the component elements you're about to generate
                                        let counter_input_settings = {
                                            id             : 'username',
                                            label          : 'Create Your Username:',
                                            name           : 'username',
                                            placeholder    : 'Enter a username',
                                            max_characters : 30,
                                            required       : true
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let counter_input = counter_inputs.generate( counter_input_settings );

                                    </script>