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

[Feature Request] Currency Input #11495

Closed
mczarnobai opened this issue May 26, 2020 · 2 comments
Closed

[Feature Request] Currency Input #11495

mczarnobai opened this issue May 26, 2020 · 2 comments
Assignees

Comments

@mczarnobai
Copy link

Problem to solve

I was not successful when trying to use a currency mask for the v-text-field component. I found no way to allow only numbers with 2 decimal places

Proposed solution

v-text-field
prefix="$"
type="decimal"
precision="2"

@ghost ghost added the S: triage label May 26, 2020
@va-b
Copy link

va-b commented May 27, 2020

My solution, may be useful for you

<v-text-field
		:label="label" :readonly="readonly" :disabled="disabled" :rules="rules"
		v-model.trim="innerValue"
		@focus="focus"
		@blur="isInFocus = false"
		@click:clear="innerValue = ''"
/>

@Component
export default class MyFloatInput extends Vue
{
	@Prop({required: true}) value!: number|null;
	@Prop({required: true, type: String}) label!: string;
	@Prop({default: false, type: Boolean}) readonly!: boolean;
	@Prop({default: false, type: Boolean}) disabled!: boolean;
	@Prop({default: () => [], type: Array}) rules!: Function[];

	private isInFocus: boolean = false;
	private innerText: string = '';

	private focus()
	{
		this.innerText = !!this.value ? this.value.toString() : '';
		this.isInFocus = true;
	}

	private blur()
	{
		this.isInFocus = false;
		this.innerText = !!this.value ? this.value.toString() : '';
	}

	private get innerValue(): string
	{
		return this.isInFocus
			? this.innerText
			: this.$l[this.value ?? ''];
	}
            private format(v): string
            {
               return !isNaN(+v) 
               ? new Intl.NumberFormat(this.localeCode, {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(+v)
               : ''
           }


	private set innerValue(v: string)
	{
		if(v === '')
		{
			this.innerText = '';
			this.$emit('input', null);
		}
		if(/^\-?\d+(\.|\,)?\d*$/.test(v))
		{
			this.innerText = v.replace(",", ".");
			this.$emit('input', Number(Number(this.innerText).toFixed(2)));
		}
		else
		{
			this.innerText = v.replace(/([^ \d\.\,\-\s]+)|((\.|\,|\-){2,})/g, '');
		}
	}
};

@johnleider
Copy link
Member

Thank you for the Feature Request and interest in improving Vuetify. After careful consideration the team has decided that this is not functionality that we are looking to implement at this time.

If you have any additional questions, please reach out to us in our Discord community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants