MOLECULAR COMPONENTS

Password Form Group Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Password_form_group class:

    
        class Password_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',
                                            visibility_toggle_btn : 'btn btn-sm btn-link text-decoration-none'
                                        },
                                        clear_text_button_styles : 'top:-48px; -webkit-appearance:none;',
                                        clear_text_button_text   : '×',
                                        error_text_suffix        : '-error',
                                        form_modal_text : {
                                            heading: 'Password Inputs',
                                            body: [{
                                                type: 'paragraphs',
                                                content: [ 'Password Inputs are very useful and convenient options to help users enter their password data. A new practice with password inputs also allows a user to toggle the visibility of the characters they have input, in order to verify they have typed the value correctly.' ]
                                            }]
                                        },
                                        form_text : {
                                            help    : ['Default Password Input help text'],
                                            error   : ['Default Password Input error text'],
                                            success : ['Default Password Input success text']
                                        },
                                        id                      : 'default-password-id',
                                        label                   : 'Default Password Label',
                                        name                    : 'default-password-name',
                                        placeholder             : 'Enter Password',
                                        success_text_suffix     : '-success',
                                        type                    : 'password',
                                        value                   : '',
                                        visibility_default_text : 'VIEW',
                                        visibility_toggled_text : 'HIDE',
                                        required : false
                                    }
                                
                            

Methods

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

                                        // create an object with your overrides specified
                                        let password_default_settings = {
                                            id          : 'password',
                                            label       : 'Password:',
                                            name        : 'password',
                                            placeholder : 'Enter Your Password',
                                            required    : true
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let passwords = new Password_form_group(password_default_settings);

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

                                    </script>
                                
                            

get_class_defaults()

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

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

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

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

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

                                        let my_test_settings = {
                                            id          : 'password',
                                            label       : 'Password:',
                                            name        : 'password',
                                            placeholder : 'Enter Your Password',
                                            required    : true
                                        };

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

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

                                        // set your desired settings for the component elements you're about to generate
                                        let password_settings = {
                                            id          : 'password',
                                            label       : 'Password:',
                                            name        : 'password',
                                            placeholder : 'Enter Your Password',
                                            required    : true
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let password = passwords.generate( password_settings );

                                    </script>