Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min and max value options #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Component or Directive flavors
- Accept copy/paste
- Editable
- Min / Max Limits

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

Expand Down Expand Up @@ -49,7 +50,9 @@ Vue.use(money, {precision: 4})
prefix: 'R$ ',
suffix: ' #',
precision: 2,
masked: false
masked: false,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
}
}
Expand Down Expand Up @@ -79,7 +82,9 @@ Must use `vmodel.lazy` to bind works properly.
prefix: 'R$ ',
suffix: ' #',
precision: 2,
masked: false /* doesn't work with directive */
masked: false /* doesn't work with directive */,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
}
},
Expand All @@ -91,14 +96,17 @@ Must use `vmodel.lazy` to bind works properly.

## Properties

| property | Required | Type | Default | Description |
|-----------|----------|---------|---------|---------------------------------------------------------|
| precision | **true** | Number | 2 | How many decimal places |
| decimal | false | String | "." | Decimal separator |
| thousands | false | String | "," | Thousands separator |
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
| suffix | false | String | "" | Percentage for example: " %" |
| masked | false | Boolean | false | If the component output should include the mask or not |
| property | Required | Type | Default | Description |
|-----------|----------|---------|-------------------------|---------------------------------------------------------|
| precision | **true** | Number | 2 | How many decimal places |
| precision | **true** | Number | 2 | How many decimal places |
| decimal | false | String | "." | Decimal separator |
| thousands | false | String | "," | Thousands separator |
| prefix | false | String | "" | Currency symbol followed by a Space, like "R$ " |
| suffix | false | String | "" | Percentage for example: " %" |
| masked | false | Boolean | false | If the component output should include the mask or not |
| min | false | Number | Number.MIN_SAFE_INTEGER | The min value allowed |
| max | false | Number | Number.MAX_SAFE_INTEGER | The max value allowed |

### References

Expand Down
10 changes: 9 additions & 1 deletion src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<input type="tel"
:value="formattedValue"
@change="change"
v-money="{precision, decimal, thousands, prefix, suffix}"
v-money="{precision, decimal, thousands, prefix, suffix, min, max}"
class="v-money" />
</template>

Expand Down Expand Up @@ -35,6 +35,14 @@ export default {
type: String,
default: () => defaults.thousands
},
max: {
codymoorhouse marked this conversation as resolved.
Show resolved Hide resolved
type: Number,
default: () => defaults.max
},
min: {
type: Number,
default: () => defaults.min
},
prefix: {
type: String,
default: () => defaults.prefix
Expand Down
14 changes: 13 additions & 1 deletion src/docs/docs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
</label>
</div>
</div>
<div class="column col-2 col-sm-3">
<label class="form-label" for="min">Min</label>
</div>
<div class="column col-2 col-sm-3">
<input class="form-input" type="number" id="min" v-model="config.min" />
</div>
<div class="column col-2 col-sm-3">
<label class="form-label" for="max">Max</label>
</div>
<div class="column col-2 col-sm-3">
<input class="form-input" type="number" id="max" v-model="config.max" />
</div>
</div>

<hr />
Expand Down Expand Up @@ -113,7 +125,7 @@ export default {
price: 1234.5,
priceDirective: 5432.1,
priceVuetify: 6789.10,
config: {decimal: ',', thousands: '.', prefix: 'R$ ', suffix: ' #', precision: 2, masked: false}
config: {decimal: ',', thousands: '.', prefix: 'R$ ', suffix: ' #', precision: 2, masked: false, max: 100000, min: -100000}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export default {
suffix: '',
thousands: ',',
decimal: '.',
precision: 2
precision: 2,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
}
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import defaults from './options'

function format (input, opt = defaults) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codymoorhouse
Input var can be a string. If decimal is ',' then input can be like '10,000'

if (typeof input === 'number') {
if (input > opt.max) {
input = opt.max
} else if (input < opt.min) {
input = opt.min
}
input = input.toFixed(fixed(opt.precision))
}
var negative = input.indexOf('-') >= 0 ? '-' : ''
Expand Down