Giter Site home page Giter Site logo

venzhyk / ng-bootstrap-form-generator Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 107 KB

Angular 2 + Bootstrap 4 Form Generator. Library provides Angular components that help quickly generate Bootstrap Form from JavaScript object (CLOSED)

TypeScript 100.00%

ng-bootstrap-form-generator's Introduction

Bootstrap4 + Angular2 Form Generator

Generate simple Bootstrap4 forms from JavaScript

Library provides Angular components that help quickly generate Bootstrap Form from JavaScript object. Component supports validators, help messages, and error messages.

Based on ReactiveFormsModule from @angular/forms. Available custom and all angular built-in validators.

Demo

Install

Add npm package

Install npm package into your Angular 2 application

npm install --save ng-bootstrap-form-generator

Once installed you need to import the main module.

Import the BootstrapFormGeneratorModule module into your app module and add it to your app module's imports

import { BootstrapFormGeneratorModule } from 'ng-bootstrap-form-generator';
@NgModule({
    imports: [BootstrapFormGeneratorModule, ...]
})
export class AppModule {
} 

Add Bootstrap and jQuery

Add css and scripts into your index.html

<!doctype html>
<html>
  <head>

  ...

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ"
      crossorigin="anonymous">
  </head>

  <body>
          <app-root>Loading...</app-root>

    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/tether/1.3.1/js/tether.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
  </body>
</html>

Check Bootstrap 4 Download page for more details

Dependencies

Usage

Full Demo: https://embed.plnkr.co/oFBOR6C1ylYquLA8oA4G

Create your data model object

 data =  {
    id: '123',
    email: '[email protected]',
    name: 'Mobibob',
    password: 'AOe30&^@#!c2',
    howUserFindUs: '2',
    agreement: true,
  }

Defile Form config

formConfig = this.formConfig = [
      {
        field: 'id',
        type: 'hidden',
      },
      {
        field: 'email',
        type: 'email',
        title: 'Email',
        helpText: 'We will send confirmation email in order to finish registration',
        required: true
      },
      {
        field: 'name',
        type: 'text',
        title: 'User Name',
        required: true,
        maxlength: 15
      },
      {
        field: 'password',
        type: 'password',
        title: 'Password',
        helpText: 'Password should be strong',
        required: true,
        minlength: 6
      },
      {
        field: 'howUserFindUs',
        type: 'select',
        title: 'How did you find us?',
        helpText: 'You can keep this field empty',
        select: {
          emptyText: '-- How did you hear of us? --',
          options: [
            { text: 'Facebook', value: 1 },
            { text: 'LinkedIn', value: 2 },
            { text: 'Google', value: 3 },
            { text: 'Friends', value: 4 },
          ]
        }
      },
      {
        field: 'agreement',
        type: 'checkbox',
        title: 'I accept license agreement',
        helpTextHtml: 'Read <a href="#license  ">license</a> before accept',
        requiredTrue: true,
        validationMessage: {
          required: 'Please, read and accept agreement'
        },
      }
    ];

Initialize bfg-form

Snippet below will generate all form fields

<bfg-form [options]='formConfig' [(value)]='data'></bfg-form>

Also, you can add your own header and footer into bfg-form

<bfg-form [options]='formConfig' [(value)]='data' #regForm>
  <bfg-before>
    <h5>New User</h5>
  </bfg-before>
  <bfg-after>
    <button type="button" class="btn btn-primary" (click)='sendForm(regForm.value, regForm.form.valid)'>Register</button>
    <button type="button" class="btn btn-default" (click)='reset()'>Clear</button>
    <span>{{message}}</span>
  </bfg-after>
</bfg-form>

demo-form

ng-bootstrap-form-generator's People

Contributors

superopengl avatar venzhyk avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ksarpotdar

ng-bootstrap-form-generator's Issues

Using ng-bootstrap-form-generator in multi-module Angular app

I'm trying to use ng-bootstrap-form-generator in a multi-module Angular app.

I've imported BootstrapFormGeneratorModule in the main AppModule even though it isn't used there.

AppModule imports a module called BootstrapModule, which imports all the modules that have components in them.

BootstrapFormGeneratorModule is in my EntryModule, which has my login and register components. I've tried to use the form generator on my login form (EntryModule also imports BootstrapFormGeneratorModule).

The full code is available here: https://github.com/TheMagnificent11/LunchVoting/tree/feature/12_form-generator

This is the error I'm getting.

vendor.js:52783 Uncaught Error: Unexpected value 'BootstrapFormGeneratorModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
    at syntaxError (vendor.js:52783)
    at vendor.js:66487
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (vendor.js:66470)
    at JitCompiler._loadModules (vendor.js:77915)
    at JitCompiler._compileModuleAndComponents (vendor.js:77888)
    at JitCompiler.compileModuleAsync (vendor.js:77817)
    at PlatformRef_._bootstrapModuleWithZone (vendor.js:16812)
    at PlatformRef_.bootstrapModule (vendor.js:16798)
    at Object.options.path (boot.browser.ts:23)

Do you know what I'm doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.