New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-editme

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-editme

Convert your AngularJS input and textarea elements to be edited inline ala LinkedIn profiles.

  • 1.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

angular-editme

Convert your AngularJS input and textarea elements to be edited inline ala LinkedIn profiles.

alt text

Demo

Check out a working example on the demo page.

Installation

  • npm install angular-editme or
  • bower install angular-editme or
  • jspm install npm:angular-editme or
  • Download and add to your html file

Usage

Add the shaka-editme module as a dependency to your Angular app's main module:

Installed with global:
angular.module('app', ['shaka-editme']);
Installed with npm:
let angular = require('angular');
angular.module('app', [require('angular-editme')]);
Installed with jspm:
import editme from 'angular-editme';
angular.module('app', [editme]);
Basic example

To convert an existing input element into an editable element wrap it with the <sk-editme> directive.

<form name="demo">
  ...
  <sk-editme>
    <input type="text" name="location" ng-model="locale" ng-required="true">
  </sk-editme>

  <sk-editme>
    <textarea name="description" ng-model="body" ng-required="true"></textarea>
  </sk-editme>
</form>

The <sk-editme> directive has the following requirements:

  • It must wrap a single <textarea> or <input type="text|url|date|email|week|month|number|time"> element.
  • The element wrapped element must have a valid ng-model attirbute.
Handling invalid input

An editable field in edit-state will remain so until a user enters a valid value. If a user enters an invalid or empty value the field will remain in the edit-state until a valid value is entered. The validity of the field is governed by the ngModel validators of the wrapped element.

Example:

Will validate user has entered valid email before exiting edit-state.

<sk-editme>
  <input type="email" name="email" ng-model="email" ng-required="true">
</sk-editme>

Will validate user has entered only numbers before exiting edit-state.

<sk-editme>
  <input type="text" ng-model="number" name="number" ng-pattern="/\d+/" />
</sk-editme>
Interacting with directive from your Controller

Given markup styled with Bootstrap we can add the has-error class to the form-group element when the edmitme directive is invalid, and then remove it when the directive is valid.

index.html

<!--
  on-change - will be triggered when input loses focus and the value is both changed and valid.
  on-invalid - will be triggered when input loses focus and the value is invalid
-->
<div ng-controller="DemoController as demo">
  <div class="form-group" ng-class="{'has-error': demo.isInvalid}">
    <label>Email</label>
    <sk-editme on-change="demo.onChange($value)" on-invalid="demo.onInvalid($error)">
      <input type="email" name="email" ng-model="demo.email">
    </sk-editme>
  </div>
</div>

demo.controller.js

.controller('DemoController', function(userService) {
  let vm = this;

  vm.email = 'myemail@email.com';
  vm.isInvalid = false;

  /**
   * The value arg will be the current valid value from the input.
   * (same as vm.email in this case)
   */
  vm.onChange = (value) => {
    vm.isInvalid = false;
    userService.saveEmail(value);
  };

  /**
   * The $error arg will be the input's ngModel $error object
   * See $error in https://docs.angularjs.org/api/ng/type/form.FormController
   */
  vm.onInvalid = ($error) => {
    vm.isInvalid = true;
  };
})

API

All properties are optional.

<sk-editme
  is-editing="{Boolean}"
  hide-icon="{Boolean}"
  on-change="{Expression}"
  on-invalid="{Expression}"
  on-state-change="{Expression}"
>
</sk-editme>
NameTypeDescriptionDefault
isEditingBooleanCan be set to true if you want to start in edit modefalse
hideIconBooleanWill hide pencil icon if set to truefalse
onChangeExpression(Function)Expression will be evaluated when input loses focus and the entered value is both changed and valid. The valid value is available as $value.
onInvalidExpression(Function)Expression will be evaluated when input loses focus and the entered value is invalid. The ngModel error is available as $error.
onStateChangeExpression(Function)Expression will be evaluated when the directive changes to and from edit mode. A Boolean value $isEditing is availble to determine the current state.

Keywords

FAQs

Package last updated on 28 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc