Coder Social home page Coder Social logo

snj / ngtageditor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from varyoo/ngtageditor

0.0 3.0 0.0 146 KB

A new lightweight tag input, built for AngularJS

Home Page: http://varyoo.github.io/ngTagEditor

License: GNU General Public License v3.0

CSS 23.44% HTML 32.53% JavaScript 44.03%

ngtageditor's Introduction

ngTagEditor: AngularJS tag input, editor

A new tag input, built for AngularJS

Demo

See the live demo page here.

Installation

Add the following files to your application:

<link rel="stylesheet" href="ngTagEditor.css" type="text/css"/>
<script type="text/javascript" src="http://cdn.jsdelivr.net/angularjs/1.2.17/angular.min.js"></script>
<script type="text/javascript" src="ngTagEditor.js"></script>

Usage

Basic usage

<tag-editor></tag-editor> In your html in any form.

It will add a hidden input <input type="hidden" name="tags"> containing added tags name, separated by a comma.

Advanced usage

Initializing tags

Add something like that to your javascript code:

var app = angular.module('app', ['ngTagEditor']);
app.controller('RandomController', function($scope, $http) {
	$scope.tags = [
		{name: 'See'},
		{name: 'how'},
		{name: 'amazing'},
		{name: 'is'},
		{name: 'AngularJS'}
	];
});

That goes with the following html:

<form ng-controller="RandomController">
	<tag-editor ng-model="tags" output="name"></tag-editor>
</form>

Available options

You can pass options by the following way: <tag-editor option="value"></tag-editor>.

name  values description default
output name, id If you use suggestions, id will replace tag names by tag ids from your database in the hidden input. name
fetch any valid API URL required to suggest tags while the user is typing, this way, you can save ids instead of names (see output). The API output, must be formated properly, see Suggestions paragraph bellow. "url/to/my/api.php?query="
placeholder any string Text to display as input placeholder "Enter a few letters..."
Suggestions

First, give the URL of your API through the fetch option. The data must be formated as follow, as stated this article.

{
    "status": "success",
    "data": [{
        "id": "45",
        "name": "Say"
    }, {
        "id": "23",
        "name": "Hello"
    }, {
        "id": "68",
        "name": "to"
    }, {
        "id": "77",
        "name": "JSON"
    }]
}

Exemple

See test.html

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.