MOLECULAR COMPONENTS

Custom Checkbox Orphan Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Custom_checkbox_orphan_component class:

    
        class Custom_checkbox_orphan_component {
            
            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 : {
                                            checkbox_parents : 'custom-control custom-checkbox mb-4',
                                            checkboxes : 'custom-control-input',
                                            checkbox_labels : 'custom-control-label'
                                        },
                                        id : 'custom-checkbox-orphan-id',
                                        name : 'custom-checkbox-orphan-name',
                                        aria_describedby_suffix : '-label',
                                        label : 'Custom Orphan Checkbox Default',
                                        value : 'default',
                                        checked : false
                                    }
                                
                            

Methods

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

                                        // create an object with your overrides specified
                                        let orphan_default_settings = {
                                            checked: true
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let orphans = new Custom_checkbox_orphan_component(orphan_default_settings);

                                        // confirm your changes
                                        console.log( orphans.defaults.checked );

                                    </script>
                                
                            

get_class_defaults()

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

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

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

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

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

                                        let my_test_settings = {
                                            checked: true
                                        };

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

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

                                        // set your desired settings for the component elements you're about to generate
                                        let remember_checkbox_settings = {
                                            name : 'remember-me',
                                            label : 'Remember Me',
                                            value : 'remember_me'
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let remember_checkbox = orphans.generate( remember_checkbox_settings );

                                    </script>