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

Support min/max limits #27

Open
wants to merge 2 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
9 changes: 7 additions & 2 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 Range.

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: 0,
max: 10000
}
}
}
Expand Down Expand Up @@ -79,7 +82,7 @@ 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 */,
}
}
},
Expand All @@ -99,6 +102,8 @@ Must use `vmodel.lazy` to bind works properly.
| 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 | null | Limit min value, when null no limit |
| max | false | Number | null | Limit max value, when null no limit |

### References

Expand Down
2 changes: 1 addition & 1 deletion dist/v-money.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 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 @@ -42,6 +42,14 @@ export default {
suffix: {
type: String,
default: () => defaults.suffix
},
min: {
type: Number,
default: () => defaults.min
},
max: {
type: Number,
default: () => defaults.max
}
},

Expand All @@ -67,6 +75,12 @@ export default {

methods: {
change (evt) {
var unMaskedValue = unformat(evt.target.value, this.precision)
if (this.min !== null && unMaskedValue < this.min) {
evt.target.value = format(this.min, this.$props)
} else if (this.max !== null && unMaskedValue > this.max) {
evt.target.value = format(this.max, this.$props)
}
this.$emit('input', this.masked ? evt.target.value : unformat(evt.target.value, this.precision))
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/docs/docs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@
<div class="column col-2 col-sm-3">
<input class="form-input" type="text" id="thousands" v-model="config.thousands" />
</div>

<div class="column col-2 col-sm-3">
<label class="form-label" for="thousands">Min</label>
</div>
<div class="column col-2 col-sm-3">
<input class="form-input" type="number" id="minValue" v-model.number="config.min" />
</div>

<div class="column col-2 col-sm-3">
<label class="form-label" for="thousands">Max</label>
</div>
<div class="column col-2 col-sm-3">
<input class="form-input" type="number" id="maxValue" v-model.number="config.max" />
</div>

<div class="column col-4 col-sm-5">
<div class="form-group">
<label class="form-checkbox">
Expand Down Expand Up @@ -113,7 +128,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, min: 0, max: 100}
}
}
}
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: null,
max: null
}