Getting Started
Setup is easy and designed to be highly modular. Just follow these steps in order:
- Include AngularJS
- Include Angular Dataform in one of the following ways:
- Include the entire library (located in the
/dist
directory) - Include
/common/module.js
and any directives you wish to use
- Include the entire library (located in the
- Add the
'dataform'
module as a dependency:angular.module('myModule', ['dataform'])
Autocomplete datalist
What?
Adds autocomplete menus to input fields. Inspired by the HTML5 <datalist> element.
City: {{cityName}}
Active index: {{activeIndex}}
- {{c.name}}
- {{cityName}} (add new city)
How?
<input ng-model="cityName" df-autocomplete-datalist="cities"> <ol df-datalist id="cities"> <li ng-repeat="c in cities|filter:{name:cityName}|limitTo:5" df-value="c.name">{{c.name}}</li> <li ng-show="query" df-value="query"> {{query}} <span>(add new city)</span> </li> </ol>
- Create an <input> with
df-autocomplete-datalist="some-id"
, where#some-id
is the corresponding list element (below). - Create an
<ol df-datalist id="some-id">
. Any list item with adf-value="expr"
attribute will be selectable. Useng-repeat
or any other AngularJS/HTML to build the list of autocomplete choices. - To select the first list item by default (instead of having no selection), specify
df-initial-selection=0
on the<ol>
.
Tags
What?
A tag list bound to an array that lets you add/remove tags and customize the way tags are displayed.
Horizontal
Horizontal (add on new line)
Vertical
How?
<ol df-tag-list items="tags"> <li df-tag ng-repeat="tag in items"> <a ng-href="#{{tag}}">{{tag}}</a> </li> <li df-tag-add></li> </ol>
- Add
df-tag-list
anditems="arrayExpr"
to an OL or UL. - Add list items with
df-tag
(likely usingng-repeat
to loop overitems
, which is equal to yourarrayExpr
). - If you want a way to add new tags, add a list item with
df-tag-add
. You can leave its contents empty to use the default form, or you can specify your own form (it must contain both a<form>
and<input>
).
Object Input
What?
An input field that has an object-valued ngModel and displays one of the object's fields.
How?
<input df-object-input ng-model=obj display-field="color">
Object Autocomplete
What?
Autocomplete objects, not just strings.
City: {{city}}
- {{c.name}}
- {{city.name}} (add new city)
How?
<form> <input ng-model="city" df-object-input display-field="name" df-autocomplete-datalist="cityObjects" placeholder="City"> <button ng-click="city = null" ng-show="city.name">Reset</button> </form> <ol df-datalist id="cityObjects"> <li ng-repeat="c in cities|filter:{name:city.name}|limitTo:5" df-value="c">{{c.name}}</li> <li ng-show="city.name" df-value="{name: city.name, new: true}"> {{city.name}} <span>(add new city)</span> </li> </ol>