SB-forms Components & Configurations

List Of Components

Component

InputType

Description

Component

InputType

Description

Textbox

text

Component used to render textbox

Textarea

textarea

Component used to render textarea

Checkbox

checkbox

Component used to render checkbox

Select

select

Component used to render dropdown with single select

MultiSelect

nestedselect

Component used to render dropdown with multi select

Topic Selector

topicselector

Component used to render topic selector

Timer

timer

Component used to render time

Keywords

keywords

Component used to render input tags

Framework

framework

Component used to render dropdown with framework values

FrameworkCategorySelect

frameworkCategorySelect

Component used to render dropdown with framework categories.

Field Configuration Properties

 

{ "code": string, // property to match the backend schema ("name", "description", etc...) "name": string, // name of the field ("Name", "Board", "Medium", "License", "Copyright Year", etc) "label": string, // title of the field "placeholder": string, // placeholder text to appear within the field "description": string, // to specify description about the field and to show as tooltip "default": string, // specify default value "dataType": string, // to specify the datatype of the field outcome ("list", "number", "text") "inputType": string, // to map the field type and the component ("text", "textarea", "select", "nestedselect", etc) "editable": boolean, // to enable or disable the field "required": boolean, // to specify if the field is mandatory or not (currently, not used.) "visible": boolean, // to hide or show the field "depends": array, // array of "code" to specify that this field is dependant on other fields "range": array, // Array or array of objects of inputs to fields such as "select", "nestedselect", "multiselect" "options": array/function/map, // to specify the inputs to fields such as "select", "nestedselect", "multiselect", "framework", "frameworkCategorySelect" "renderingHints": json, // to specify any additional configuration ex:({"class": "sb-g-col-lg-1 required"}) "validations": array // Array of objects to specity the validations of a field. Each validation object takes properties such as "type", "message", "value", "criteria" "output": string, // this field is specific to framework terms and it's associations. The field will decide the property for the field outcome ex:("name", "label", "identifier") "sourceCategory": string, // this field is specific to framework categories to map the category and association ex: (to map "subjectIds" with "subject" or to map "targetMediumIds" with "medium") "terms": array, // Array or array of object of inputs to fields related to framework and it's categories }

 

Sample Configuration for name field:

{ "code": "name", "name": "Name", "label": "Title", "placeholder": "Title", "description": "Name of the content", "dataType": "text", "inputType": "text", "editable": true, "required": true, // currently not used to check if the field is mandatory. // "visible": true, "renderingHints": { "class": "sb-g-col-lg-1 required" }, "validations": [ { "type": "maxLength", "value": "120", // maximum number of characters "message": "Input is Exceeded" }, { "type": "required", "message": "Title is required" } ] },


Custom invocation when a field’s value changes:

FORMCONTROL.valueChanges.pipe( tap((value) => { // custom logic }) );

Custom invocation when a dependant field values changes:

 

Custom validation:

Let’s say we have two fields, maxTime and warningTime and assume that the condition here is warningTime should not be greater than maxTime

We introduced a new type of validations called compare:

Here, criteria is a map which takes any comparison operator as the key and array of codes as value.

Following is our custom function to compare two fields and handle errors if any. The function takes two arguments - criteria and AbstractControl.

Now the function can be passed to Angular by doing Validators.compose as shown below:

Function compareFields will now be called whenever warningTime field is changes.

 

Custom Event Listener:

Angular by default provides two methods to listen to any field’s changes.

  1. FormControl.valueChanges

  2. FormControl.statusChanges

The above two methods will be immediately triggered when there is a change in the field.

Let’s assume we have a scenario where we need to make an async API call and make use of the API response, the above two methods will not help us as the API might have a delay.

To tackle this scenario, we will introduce a custom event emitter on the FormControl.

The following interface extends the default Angular FormControl and adds a RxJS Subject event emitter.

This will help us emit the event when the API returns a response

Any other fields that are dependant on this API response can now listen to this event emitter.

 


 

IN PROGRESS

Closure function:

A closure function takes the following objects as its arguments.

Sample Closure function:

Let’s say we have a field called framework. On change of framework field, if we have to invoke a logic, it can be achieved as shown below:

During the initialisation of the framework field, we will pass the following function to options property of framework field.

Field Config for framework