MOLECULAR COMPONENTS

Phone Input Form Group Component

DEFAULT EXAMPLE:

Overview

Here is an overview of the Phone_input_form_group class:

    
        class Phone_input_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',
                                            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'
                                        },
                                        aria_describedby_suffix  : '-help',
                                        error_text_suffix        : '-error',
                                        success_text_suffix      : '-success',
                                        clear_text_button_styles : 'top:-48px; -webkit-appearance:none;',
                                        clear_text_button_text   : '×',
                                        id                       : 'default-phone-input-id',
                                        name                     : 'default-phone-input-name',
                                        value                    : '',
                                        label                    : 'Default Phone Input Label',
                                        placeholder              : '(123) 123-1234',
                                        form_text : {
                                            help    : ['Default Phone Input help text'],
                                            error   : ['Default Phone Input error text'],
                                            success : ['Default Phone Input success text']
                                        },
                                        form_modal_text : {
                                            heading: 'Form Phone Inputs',
                                            body: [{
                                                type: 'paragraphs',
                                                content: [ 'Form Phone Inputs are very useful and convenient options to help users enter telephone number data. This phone input comes with JavaScript masking built-in from a third-party plugin calles iMask.js!' ]
                                            }]
                                        },
                                        masking : {
                                            enable : true,
                                            type   : 'phone_us'
                                        },
                                        required : false
                                    }
                                
                            

Methods

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

                                        // create an object with your overrides specified
                                        let phone_default_settings = {
                                            id    : 'phone',
                                            name  : 'phone',
                                            label : 'Phone Number:'
                                        };

                                        // initialize the class and pass your settings as an argument
                                        let phones = new Phone_input_form_group(phone_default_settings);

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

                                    </script>
                                
                            

get_class_defaults()

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

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

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

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

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

                                        let my_test_settings = {
                                            id    : 'phone',
                                            name  : 'phone',
                                            label : 'Phone Number:'
                                        };

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

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

                                        // set your desired settings for the component elements you're about to generate
                                        let phone_settings = {
                                            id    : 'phone',
                                            name  : 'phone',
                                            label : 'Phone Number:'
                                        };

                                        // generate the component nodes to spec by passing your settings in
                                        let phone = phones.generate( phone_settings );

                                    </script>