MOLECULAR COMPONENTS

Textarea Character Counter Form Group Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Textarea_character_counter_form_group class:

    
        class Textarea_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:

                                
                                    {
                                        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',
                                            textareas                 : 'form-control',
                                            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'
                                        },
                                        aria_describedby_suffix  : '-help',
                                        error_text_suffix        : '-error',
                                        success_text_suffix      : '-success',
                                        characters_count_suffix  : '-characters',
                                        max_characters           : '1200',
                                        clear_text_button_styles : 'top:-82px; -webkit-appearance:none;',
                                        clear_text_button_text   : '×',
                                        rows                     : '4',
                                        id      : 'char-textarea-id',
                                        name    : 'char-textarea-name',
                                        value   : '',
                                        label   : 'Character Counter Textarea',
                                        form_text : {
                                            help    : ['Default Textarea help text'],
                                            error   : ['Default Textarea error text'],
                                            success : ['Default Textarea success text']
                                        },
                                        form_modal_text : {
                                            heading: 'Textarea Inputs',
                                            body: [{
                                                type: 'paragraphs',
                                                content: [ 'Textarea Inputs are very useful and convenient options to help users enter data. Textareas differ from traditional inputs by allowing desktop browser users to re-size the input, and allowing both desktop and mobile browsers to scroll vertically whenever longer content is entered.' ]
                                            }]
                                        },
                                        required : false
                                    }
                                
                            

Methods

The following class methods allow you to interact with the Textarea_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 { Textarea_character_counter_form_group } from './js/modules/form_components.js';

                                        // create an object with your overrides specified
                                        let textarea_default_settings = {
                                            max_characters : 270,
                                            id             : 'description',
                                            name           : 'description',
                                            label          : 'Page Description:'
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let textareas = new Textarea_character_counter_form_group(textarea_default_settings);

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

                                    </script>
                                
                            

get_class_defaults()

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

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

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

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

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

                                        let my_test_settings = {
                                            max_characters : 270,
                                            id             : 'description',
                                            name           : 'description',
                                            label          : 'Page Description:'
                                        };

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

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

                                        // set your desired settings for the component elements you're about to generate
                                        let textarea_settings = {
                                            max_characters : 270,
                                            id             : 'description',
                                            name           : 'description',
                                            label          : 'Page Description:'
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let textarea = textareas.generate( textarea_settings );

                                    </script>