Skip to content

Commit 45102ed

Browse files
author
Cody Moorhouse
committed
Add min and max value options
1 parent 694fecf commit 45102ed

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Component or Directive flavors
1111
- Accept copy/paste
1212
- Editable
13+
- Min / Max Limits
1314

1415
For other types of mask, use [vue-the-mask](https://vuejs-tips.github.io/vue-the-mask)
1516

@@ -49,7 +50,9 @@ Vue.use(money, {precision: 4})
4950
prefix: 'R$ ',
5051
suffix: ' #',
5152
precision: 2,
52-
masked: false
53+
masked: false,
54+
min: -1000000000,
55+
max: 1000000000,
5356
}
5457
}
5558
}
@@ -79,7 +82,9 @@ Must use `vmodel.lazy` to bind works properly.
7982
prefix: 'R$ ',
8083
suffix: ' #',
8184
precision: 2,
82-
masked: false /* doesn't work with directive */
85+
masked: false /* doesn't work with directive */,
86+
min: -1000000000,
87+
max: 1000000000
8388
}
8489
}
8590
},
@@ -91,14 +96,17 @@ Must use `vmodel.lazy` to bind works properly.
9196

9297
## Properties
9398

94-
| property | Required | Type | Default | Description |
95-
|-----------|----------|---------|---------|---------------------------------------------------------|
96-
| precision | **true** | Number | 2 | How many decimal places |
97-
| decimal | false | String | "." | Decimal separator |
98-
| thousands | false | String | "," | Thousands separator |
99-
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
100-
| suffix | false | String | "" | Percentage for example: " %" |
101-
| masked | false | Boolean | false | If the component output should include the mask or not |
99+
| property | Required | Type | Default | Description |
100+
|-----------|----------|---------|-------------|---------------------------------------------------------|
101+
| precision | **true** | Number | 2 | How many decimal places |
102+
| precision | **true** | Number | 2 | How many decimal places |
103+
| decimal | false | String | "." | Decimal separator |
104+
| thousands | false | String | "," | Thousands separator |
105+
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
106+
| suffix | false | String | "" | Percentage for example: " %" |
107+
| masked | false | Boolean | false | If the component output should include the mask or not |
108+
| min | false | Number | -1000000000 | The min value allowed |
109+
| max | false | Number | 1000000000 | The max value allowed |
102110

103111
### References
104112

src/component.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export default {
3535
type: String,
3636
default: () => defaults.thousands
3737
},
38+
max: {
39+
type: Number,
40+
default: () => defaults.max
41+
},
42+
min: {
43+
type: Number,
44+
default: () => defaults.min
45+
},
3846
prefix: {
3947
type: String,
4048
default: () => defaults.prefix

src/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ export default {
33
suffix: '',
44
thousands: ',',
55
decimal: '.',
6-
precision: 2
6+
precision: 2,
7+
min: -1000000000,
8+
max: 1000000000
79
}

src/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import defaults from './options'
22

33
function format (input, opt = defaults) {
44
if (typeof input === 'number') {
5+
if (input > opt.max) {
6+
input = opt.max
7+
} else if (input < opt.min) {
8+
input = opt.min
9+
}
510
input = input.toFixed(fixed(opt.precision))
611
}
712
var negative = input.indexOf('-') >= 0 ? '-' : ''

0 commit comments

Comments
 (0)