Giter Club home page Giter Club logo

jquery-priceformat's Introduction

jQuery Price Format

jQuery plugin to format price inputs

jQuery price format is a plugin used to format input fields into fields capable to contain price. It limits the input field to able to receive only numbers, and automatically inserts the decimal point
as you type. Such functionality is needed when developing accounting applications or online shops or anything that require a price like input.

Install via bower

You can install the package using bower
bower install jquery.priceformat --save

Example Usage

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title></title>
</head>
<body>

<label for="price">Price: </label>
<input id="price" type="text"/>

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.priceformat.js"></script>
<script type="text/javascript">
 $(document).ready(function () {
     $('#price').priceformat({
         defaultValue: 10050,
         decimalSeparator: '.',
         thousandsSeparator: ','
     });
 })
</script>
</body>
</html>

The default value is 100.50, with . as a decimal separator and , as thousands separator (for example 1,300.50)

More examples are available inside the examples/ directory.

examples/jsinit.html - how to initialize via javascript
examples/datattrinit.html - how to initialize via data attributes
examples/signedunsinged.html - signed and unsigned functionality

Initializing

The plugin can be initialized manually by calling $('#field').priceformat({..options..}); or by using data-format="price" on the field itself, for example:
<input type="text" data-format="price" />

Plugin Options

The plugin can accept few options either via the constructor or html data-* attributes.

Default value integer, default = 0
Specified either via defaultValue in plugin constructor or value attribute on the input field.
Sets the initial value of the input. For example to set the initial value to 100.50, specify the default value as 10050

Decimals Separator char, default = .
Specified either via decimalSeparator in plugin constructor or data-decimal-separator attribute on the input field.
Sets the decimals separator character.

Thousands Separator char, default = null
Specified either via thousandsSeparator in the plugin constructor or data-thousands-separator attribute on the input field.
Sets the thousands separator character, default to null means no character will be used.

Allow signed numbers boolean, default = false
Specified exclusively via allowSign in the plugin constructor.
Whether to allow signed numbers. Default false. If set to true, user can change the sign of the input by using the - or + keys.

Display plus sign boolean, default = false
Specified exclusively via displayPlusSign in the plugin constructor.
Makes sense only if allowSign is set to true. By default, allowSign will have indication only for negative numbers, by pre-pending - in front of the number. If you want indication for positive numbers as well, set displayPlusSign to true.

License

The MIT License (MIT)

Copyright (c) 2014 Dmitry "skwee357" Kudryavtsev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jquery-priceformat's People

Contributors

skwee357 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.