GithubHelp home page GithubHelp logo

nvdnkpr / angular-autofields-bootstrap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from justmaier/angular-autofields-bootstrap

0.0 1.0 0.0 91 KB

Automatically generate fields from a schema object and bind them to an object

License: MIT License

angular-autofields-bootstrap's Introduction

angular-autoFields-bootstrap

Avoid bloating your templates with repetitive form html.
Instead, just specify a schema for the form and the model you want to bind it to and you're done!

Check out a demo!

##Installation

####Bower bower install angular-autoFields-bootstrap

####Nuget install-package AngularJs.AutoFields.Bootstrap

####Manually <script type="text/javascript" src="js/autoFields-bootstrap.js"></script>

##Usage

  1. If you're doing this manually, be sure to install Angular-UI Bootstrap for date popover support
  2. Include the autoFields-bootstrap.js script provided by this component into your app
  3. add autoFields as a module dependency to your app

####Javascript

angular.module('app',['autoFields'])
.controller('JoinCtrl', ['$scope', function ($scope) {
	$scope.user = {
		username: '',
		password: '',
		confirmPassword: '',
	};

	$scope.schema = [
		{ property: 'username', type: 'text', attr: { ngMinlength: 4, required: true }, msgs: {minlength: 'Needs to have at least 4 characters'} },
		{ property: 'password', type: 'password', attr: { required: true } },
		{ property: 'confirmPassword', label: 'Confirm Password', type: 'password', attr: { confirmPassword: 'user.password', required: true } }
	];

	$scope.join = function(){
		if(!$scope.joinForm.$valid) return;
		//join stuff....
	}
}]);

####Html

 <form name="joinForm" ng-submit="join()">
    <auto:fields fields="schema" data="user"></auto:fields>
    <button type="submit" class="btn btn-default btn-lg btn-block" ng-class="{'btn-primary':joinForm.$valid}" tabindex="100">Join</button>
</form>

##Field Schema

  • property the data property to bind to
  • type the type of field. Options include: checkbox, date, select, textarea, any text variation (ie. password, text, email, number)
  • label the label for the field. If no label is provided it will convert the property name to title case. If you don't want a label, set it's value to ''
  • attr any additional attributes you would like to have on the object. Camelcase is converted to dash notation. Validation properties can go here.
  • list the string that goes into ng-options for select fields
  • rows number of textarea rows (defaults to 3)
  • columns number of sm columns a field should span if the type is multiple. If this is applied at the same level as the multiple type, it will apply it to all of it's fields.
  • msgs validation messages for corresponding validation properties on the field

##Options

  • classes the classes for the different elements
  • container the html for the div the will hold the fields
  • defaultOption the text for the default select option (Select One)
  • dateSettings settings for the date fields (see angular-ui-bootstrap's date picker)
  • textareaRows the default amount of rows for a textarea (3)
  • fixUrl whether or not url type fields should have http:// auto added (true)
  • validation settings for validation
    • enabled enabled/disable validation (enabled by default)
    • showMessages enabled/disable validation messages (enabled by default)
    • defaultMsgs default validation messages when none is specified in the field schema

##Notes

  • It shares the scope of it's parent so that it can access the data on the scope
  • If you would like to add another type of field or you run into any bugs, please submit a pull request!

angular-autofields-bootstrap's People

Contributors

justmaier avatar

Watchers

 avatar

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.