0.0.3 • Published 2 years ago

lala-reactive-prog v0.0.3

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

Author Note

This library is created to make frontend developers life easy and this can help devs to save their time for building HTML/CSS JAvascript even angular coding for the same repeatative form for any enterprise application mostly useful for ERP, CRM, Fintech Apps

Thanks, Lala Mohammad Umar

Howto

your *.component.ts

import { Component, Input, OnChanges } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { ControlBase } from 'lala-reactive-prog/lib/controls/control-base';
import { DataService } from 'lala-reactive-prog/lib/data.service';
import { MetaService } from 'lala-reactive-prog/lib/meta.service';

@Component({
  selector: 'app-lala-form',
  templateUrl: './lala-form.component.html',
  styleUrls: ['./lala-form.component.scss'],
})
export class lalaFormComponent implements OnChanges {
  @Input() meta: ControlBase[] = [];
  @Input() data: any = {};
  form!: FormGroup;
  payLoad = '';

  constructor(private metaService: MetaService,private dataService: DataService) {}

  async ngOnChanges() {
    this.data = await this.dataService.getData("url");
    this.metadata = await this.metaService.getMeta("url");
    this.form = this.metaService.toFormGroup(this.meta, this.data);
  }

  onSubmit() {
    this.payLoad = JSON.stringify(this.form.getRawValue());
  }
}

*.component.html

<div>
  <form (ngSubmit)="onSubmit()" [formGroup]="form">
    <div *ngFor="let control of metadata" class="form-row">
      <app-control [control]="control" [form]="form"></app-control>
    </div>

    <div class="form-row">
      <button type="submit" class="btn btn-primary" [disabled]="!form.valid">Save</button>
    </div>
  </form>

 
</div>

sample metadata for form feilds

[
  {
    "key": "country",
    "options": [
      {
        "key": "IN",
        "value": "India"
      },
      {
        "key": "UAE",
        "value": "United Arab of Emirates"
      },
      {
        "key": "UK",
        "value": "United Kingdom"
      }
    ],
    "order": 8,
    "controlType": "dropdown"
  },
  {
    "controlType": "label",
    "order": 7,
    "text": "Country:"
  },
  {
    "controlType": "label",
    "order": 1,
    "text": "First Name:"
  },
  {
    "controlType": "textinput",
    "key": "firstName",
    "required": true,
    "order": 2
  },
  {
    "controlType": "label",
    "order": 3,
    "text": "Last Name:"
  },
  {
    "controlType": "textinput",
    "key": "lastName",
    "required": true,
    "order": 4
  },
  {
    "controlType": "textinput",
    "key": "emailAddress",
    "label": "Email",
    "order": 6
  },
  {
    "controlType": "label",
    "order": 5,
    "text": "Email address:"
  },
  {
    "controlType": "checkbox",
    "key": "resident",
    "label": "I'm a resident",
    "order": 9
  }
]

LalaReactiveProg

This library was generated with Angular CLI version 11.2.11.

Code scaffolding

Run ng generate component component-name --project lala-reactive-prog to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module --project lala-reactive-prog.

Note: Don't forget to add --project lala-reactive-prog or else it will be added to the default project in your angular.json file.

Build

Run ng build lala-reactive-prog to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with ng build lala-reactive-prog, go to the dist folder cd dist/lala-reactive-prog and run npm publish.

Running unit tests

Run ng test lala-reactive-prog to execute the unit tests via Karma.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI Overview and Command Reference page.

About Lala

I am fullstack developer, Love to contribute to opensource community.

TODO

1- Need customized CSS Styles to input 2- More strick rules and validation

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago