MOLECULAR COMPONENTS

Custom Checkboxes Form Group Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Custom_checkboxes_form_group class:

    
        class Custom_checkboxes_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',
                                            bordered_label_wrappers : 'd-flex justify-content-between align-items-center border-bottom mb-2',
                                            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',
                                            checkbox_parents        : 'custom-control custom-checkbox',
                                            checkboxes              : 'custom-control-input',
                                            checkbox_labels         : 'custom-control-label',
                                            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'
                                        },
                                        aria_describedby_suffix : '-help',
                                        error_text_suffix       : '-error',
                                        success_text_suffix     : '-success',
                                        group_id                : 'default-checkboxes',
                                        label                   : 'Default Custom Checkboxes',
                                        form_text : {
                                            help    : ['Custom Checkboxes help text'],
                                            error   : ['Custom Checkboxes error text'],
                                            success : ['Custom Checkboxes success text']
                                        },
                                        form_modal_text : {
                                            heading: 'Custom Checkboxes',
                                            body: [{
                                                type: 'paragraphs',
                                                content: [ 'Custom Checkboxes are Bootstrap 4 custom form elements. Custom Checkboxes leverage brand colors and CSS to replace the browser-defined styling of checkboxes.', 'Using Custom Checkboxes lets a web app provide users with checkbox elements that look/feel the same across different browsers.' ]
                                            }]
                                        },
                                        checkboxes : [
                                            {
                                                label: 'Default Checkbox 1',
                                                attributes:
                                                {
                                                    id    : 'checkbox-1',
                                                    name  : 'checkbox-1',
                                                    value : 'value1'
                                                }
                                            }
                                        ]
                                    }
                                
                            

Methods

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

                                        // create an object with your overrides specified
                                        let custom_checkboxes_default_settings = {
                                            group_id : 'marketing-offers',
                                            label    : 'Opt-In To Our:',
                                            checkboxes : [
                                                {
                                                    label: 'Weekly Newsletter',
                                                    attributes:
                                                    {
                                                        id    : 'newsletter-opt-in',
                                                        name  : 'newsletter-opt-in',
                                                        value : 'newsletter-subscribe'
                                                    }
                                                },
                                                {
                                                    label: 'Monthly Podcast',
                                                    attributes:
                                                    {
                                                        id    : 'podcast-opt-in',
                                                        name  : 'podcast-opt-in',
                                                        value : 'podcast-subscribe'
                                                    }
                                                }
                                            ]
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let custom_checkboxess = new Custom_checkboxes_form_group(custom_checkboxes_default_settings);

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

                                    </script>
                                
                            

get_class_defaults()

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

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

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

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

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

                                        let my_test_settings = {
                                            group_id : 'marketing-offers',
                                            label    : 'Opt-In To Our:',
                                            checkboxes : [
                                                {
                                                    label: 'Weekly Newsletter',
                                                    attributes:
                                                    {
                                                        id    : 'newsletter-opt-in',
                                                        name  : 'newsletter-opt-in',
                                                        value : 'newsletter-subscribe'
                                                    }
                                                },
                                                {
                                                    label: 'Monthly Podcast',
                                                    attributes:
                                                    {
                                                        id    : 'podcast-opt-in',
                                                        name  : 'podcast-opt-in',
                                                        value : 'podcast-subscribe'
                                                    }
                                                }
                                            ]
                                        };

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

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

                                        // set your desired settings for the component elements you're about to generate
                                        let custom_checkboxes_settings = {
                                            group_id : 'marketing-offers',
                                            label    : 'Opt-In To Our:',
                                            checkboxes : [
                                                {
                                                    label: 'Weekly Newsletter',
                                                    attributes:
                                                    {
                                                        id    : 'newsletter-opt-in',
                                                        name  : 'newsletter-opt-in',
                                                        value : 'newsletter-subscribe'
                                                    }
                                                },
                                                {
                                                    label: 'Monthly Podcast',
                                                    attributes:
                                                    {
                                                        id    : 'podcast-opt-in',
                                                        name  : 'podcast-opt-in',
                                                        value : 'podcast-subscribe'
                                                    }
                                                }
                                            ]
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let custom_checkboxes = custom_checkboxess.generate( custom_checkboxes_settings );

                                    </script>