0.0.70 • Published 2 years ago

@b2allsolution/factory v0.0.70

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

B2All Factory Library

B2All Factory Library is Angular library that generate form based on configuration.

Prerequisite

Angular 12 and above

Recommended

Bootstrap 5.1.3

Installation

npm install @b2allsolution/factory

Usage

Import B2allDynamicFormModule into app.module or selected module.

Add ProgressSpinnerService into providers if button is used in configuration.

@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    // import B2allDynamicFormModule
    B2allDynamicFormModule,
  ],
  providers: [
    // add ProgressSpinnerService if button is used
    ProgressSpinnerService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Example:

HTML :

<b2all-dynamic-form
  #dynamicForm="b2allDynamicForm"
  [inputFormConfigs]="config"
  [inputSavedData]="savedData"
  [inputFormName]="'form_name'"
  (formOnSubmit)="formOnSubmit($event)"
>
</b2all-dynamic-form>

Typescript :

this.config: IFieldConfig[] = [
  {
    name: 'full_name',
    display_text: 'Full name: ',
    type: EFieldConfigType.Input,
    validation_fn: getValidators([{ type: EFormValidator.Required }]),
    type_config: {
      type: EFieldConfigInputType.Text,
      list: false,
      css_class: {
        group: 'form-group mb-3',
        group_label: '',
        input: 'form-control',
        input_label: 'mb-1',
      },
    },
    css_class: 'col-12',
  },
];

this.savedData = {
  full_name: 'Daniel'
};

formOnSubmit(formValue: any): Promise<void> {
  console.log(formValue);
}

IFieldConfig Configuration

KeyTypeDescription
name?stringName of the field to be store into database as the field name
display_text?stringDisplay Text for label
value?anyValue of this control, only for single object
validation_fn?ValidatorFn[]Validation for this control
async_validation_fn?AsyncValidatorFnAsync validation for this control
disabled?booleanDisabled field (disabled field will not be store when submit)
index?numberFor field sorting
css_class?stringFor css class
typeEFieldConfigTypeIndicate field type
type_config*Futher configuration for specific type (detail is at below)

type_config Configuration

Input

KeyTypeDescription
readonly?booleanControl become readonly (undefined to disabled readonly)
type?EFieldConfigInputTypeInput type
list?booleanFor Checkbox and Radio list
dataset?IKeyValueInString[]When list is true, this field is use
input_helper?boolean?
single_checkbox_display_text?stringWhen list is false and is Checkbox, text will display beside checkbox
css_class?*Css class
placeholder?stringPlaceholder (Optional, if this field has value, display_text will not be shown)

Button

KeyTypeDescription
type'button' / 'submit'Button type
onclick_fn() => PromiseClick Event
loading_text?stringLoading Text
css_class?*Css class

Select

KeyTypeDescription
datasetIMultiSelect[]Select Dataset
controls*(#select-controls-configuration)Select control
css_class*CSS class

Array

KeyTypeDescription
hierarchy_level?IMultiSelect[]hierarchy
field_configsIFieldConfig[]FieldConfig
css_class*CSS class
table_column_names?string[]Configuration for recursive enabled template
table_column_width?string[]table column width
table_caption?stringtable caption
enable_default_options?IKeyValueInString[]default value
hideAddButton?booleanhide add button flag
hideRemoveRowItemButton?booleanhide remove row item button flag

Object

KeyTypeDescription
field_configsIFieldConfig[]FieldConfig
css_class*CSS class

Textarea

KeyTypeDescription
row_countnumberNumber of row
col_count?numberNumber of column
readonlybooleanRead Only flag
css_class*CSS class
placeholderstringplaceholder

Select controls Configuration

KeyTypeDescription
namenumberName of the control
type?'select' / 'datalistType of the control
label?stringLabel for the field
key_fieldstringKey's field name of the dataset
value_fieldstringValue's field name of the dataset
valuestringvalue
validation_fnstringValidation for the selected field
disabledstringDisabled selected control
placeholderstringplaceholder for the control
No type_config needed

RadioButtonDefault, Divider

css_class Configuration

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

0.0.70

2 years ago

0.0.69

2 years ago

0.0.62

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.65

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.59

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.51

2 years ago

0.0.50

2 years ago

0.0.47

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.44

3 years ago

0.0.45

3 years ago

0.0.46

2 years ago

0.0.40

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.29

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.26

3 years ago

0.0.23

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago