Contains Form component powered by angular 11.2.14 . This component expects a configuration and renders form according to the view.
How to use @project-sunbird/common-form-elements in your projects
- Using library locally
- Step 1: Install the package
- Step 2: Include the library selector in view( Eg .HTML file)
- Step 3: Form component emits values on every input , To get value include event callbacks
- Steps to Integrate the form
- Versions
- Build library
npm run build-lib- link library -> cd dist/common-form-elements
npm link- Link the library to your project
npm link @project-sunbird/common-form-elementsnpm install common-form-elements --save
<sb-form [config]='config'>
<sb-form (valueChanges)="function($event)" (statusChanges)="function($event)" >
Please refer following link for sample config
The Form Can render following elements:
- Text Box
- Text Area
- Drop Down (Single)
- Multi Select Drop Down
Drop Down Data Sources: Drop Down can be provided with multiple types of Data Sources:
- Static List
- Closure which is called as MARKER in above config (A function which returns Promise of FieldConfig)
- API Source - Currently Not Developed (Open For Contribution)
Example of Closure Implementation
buildStateListClosure(config: FieldConfig<any>, initial = false): FieldConfigOptionsBuilder<Location> {
return (formControl: FormControl, _: FormControl, notifyLoading, notifyLoaded) => {
return defer(async () => {
const req: LocationSearchCriteria = {
from: CachedItemRequestSourceFrom.SERVER,
filters: {
type: LocationType.TYPE_STATE
}
};
notifyLoading();
return this.fetchUserLocation(req)
.then((stateLocationList: Location[]) => {
notifyLoaded();
const list = stateLocationList.map((s) => ({ label: s.name, value: s }));
if (config.default && initial) {
const option = list.find((o) => o.value.id === config.default.id || o.label === config.default.name);
formControl.patchValue(option ? option.value : null, { emitModelToViewChange: false });
formControl.markAsPristine();
config.default['code'] = option ? option.value['code'] : config.default['code'];
}
initial = false;
return list;
})
.catch((e) => {
notifyLoaded();
this.commonUtilService.showToast('NO_DATA_FOUND');
console.error(e);
return [];
});
});
};
}
The Logic Inside can be customised to own needs of project.
Function Signature should be as follows:
functionName(config: FieldConfig<any>, initial = false): FieldConfigOptionsBuilder<T>
| Release branch | npm package version | Angular Version |
|---|---|---|
| release-5.0.1 | 5.0.1 | Ng V9 |
| release-5.1.0_v10 | 5.1.0 | Ng V10 |
| release-5.1.0_v11 | 5.1.1 | Ng V11 |
| release-5.1.0_v12 | 5.1.2 | Ng V12 |
| release-6.0.0_v13 | 6.0.0 | Ng V13 |
| release-6.0.0_v14 | 6.0.1/6.0.2/6.0.3 | Ng V14 |
| 8.0.0_v15 | 8.0.0 | Ng V15 |
| 8.0.0_v16 | 8.0.1 | Ng V16 |
The project maintains code quality through automated checks that run on every pull request:
-
Linting
- ESLint for code style and quality
- Command:
npm run lint
-
Dependencies
- Uses
npm cifor deterministic installations - GitHub Actions cache for faster builds (e.g.,
node_modules). See GitHub Actions workflow for caching configuration details.
- Uses
-
Code Formatting
- Ensures consistent code formatting
- Can be automatically fixed using
npm run lint:fix
-
Testing
- Unit tests using Karma
- Command:
npm run test
These checks ensure consistent code style, secure dependency management, and reliable testing.
Workflow automatically builds and publishes NPM packages whenever a new tag is pushed to the repository.
The workflow is triggered on:
- Triggered on push events for any Git tag
Key features of the workflow:
- Automatically builds the project
- Creates NPM package
- Publishes to NPM registry using NPM authentication token (must be provided as GitHub secret
NPM_TOKEN)