Giter Site home page Giter Site logo

codingstill / smart-type Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ktasos/smart-type

1.0 1.0 0.0 168 KB

A simple jQuery plugin that helps you bind events to a textbox typing

Home Page: http://codingstill.com/2015/08/jquery-smarttype-plugin/

HTML 66.33% JavaScript 33.67%

smart-type's Introduction

smart-type

A simple jQuery plugin that helps you bind events to a textbox when hitting Enter (e.g. saving) or hitting ESC (e.g. canceling).

The functionality it provides is very simple and its purpose is to avoid writing over and over again the same trivial code.

This plugin was initially implemented for Aptter, an internal collaboration platform for businesses.

How it works

  • When saving the onSave callback is called and the new value becomes the original.
  • When canceling the onCancel callback is called and the value returns to the original value of the textbox.

In both cases, the events trigger when the textbox has had its original value changed.

Usage

jQuery('.some-textbox').smartType({
  onSave: function (prev, current, textbox) { console.log('saving'); },
  onCancel: function (prev, current, textbox) { console.log('canceling'); }
});

Options

clearOnCancel

Clear textbox's value when canceling. Default value is false.

requireOnSave

Trigger the onSave event if the textbox is empty. Default value is false.

preventDefaultOnSave

Prevent or not the keyup event to be propagated when saving. Default value is true.

dataAttr

Specify the name of the data- attribute it will be used. Default value is val.

onSave

The callback function that is called when the user hits Enter. It has three attributes, the previous value, the current value and the textbox.

onCancel

The callback function that is called when the user hits ESC. It has three attributes, the previous value, the current value and the textbox.

Changelog

Version 0.3

Renamed to smartType from typeSave.

Version 0.2

Changed attributes for the callback functions. Cancel event occurs only when the textbox's value has changed.

Version 0.1

Initial commit. Save and Cancel events supported.

smart-type's People

Contributors

codingstill avatar ktasos avatar

Stargazers

 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.