Upload Single File Form Group Component
Overview
Here is an overview of the Upload_single_file_form_group class:
class Upload_single_file_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 : {
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 : 'position-relative text-right',
form_text_wrappers : 'd-flex justify-content-between align-items-start',
input_parents : 'bg-primary text-white text-break p-2',
inputs : 'form-control-file',
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',
img_parents : 'bg-primary text-center p-1',
imgs : 'img-fluid'
},
error_text_suffix : '-error',
form_modal_text : {
heading: 'Upload Single File Inputs',
body: [{
type: 'paragraphs',
content: [ 'Upload File Inputs help users to select and upload files, and for applications to ingest files from users. This file upload input is meant for a single file upload per instance.' ]
}]
},
form_text : {
help : ['Upload Single File help text'],
error : ['Upload Single File error text'],
success : ['Upload Single File success text']
},
id : 'upload-single-file-input-id',
label : 'Default Single File Upload',
name : 'upload-single-file-input-name',
success_text_suffix : '-success',
type : 'file',
value : '',
img_alt : '',
required : false,
accept : '',
capture : ''
}
Methods
The following class methods allow you to interact with the Upload_single_file_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 { Upload_single_file_form_group } from './js/modules/form_components.js';
// create an object with your overrides specified
let file_upload_default_settings = {
id : 'profile-img',
name : 'profile-img',
label : 'Profile Image:'
};
// initialize the class and pass your settings as an argument
let file_uploads = new Upload_single_file_form_group(file_upload_default_settings);
// confirm your changes
console.log( file_uploads.defaults.attributes.class );
</script>
get_class_defaults()
Returns an object with all of the default properties of the Upload_single_file_form_group class.
<script type="module">
// import module
import { Upload_single_file_form_group } from './js/modules/form_components.js';
// initialize the class and call the method
console.log( new Upload_single_file_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 { Upload_single_file_form_group } from './js/modules/form_components.js';
// initialize the class and call the method
console.log( new Upload_single_file_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 { Upload_single_file_form_group } from './js/modules/form_components.js';
// initialize the class and pass your settings as an argument
let file_uploads = new Upload_single_file_form_group();
let my_test_settings = {
id : 'profile-img',
name : 'profile-img',
label : 'Profile Image:'
};
// initialize the class and call the method
console.log( file_uploads.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 { Upload_single_file_form_group } from './js/modules/form_components.js';
// initialize the class and pass your settings as an argument
let file_uploads = new Upload_single_file_form_group();
// set your desired settings for the component elements you're about to generate
let file_upload_settings = {
id : 'profile-img',
name : 'profile-img',
label : 'Profile Image:'
};
// generate the component nodes to spec by passing your settings in
let file_upload = file_uploads.generate( file_upload_settings );
</script>