0

I am using ngx-mydatepicker for date field. I need to add text-mask in that code. When i tried to add i got an error as "More than one custom value accessor matches form control with unspecified name attribute".

How to add text-mask now? I used angular2-text-mask npm for text-mask. It works fine for other input field. But not in ngx-mydatepicker date field

1 Answer 1

5

I was trying to figure out the same, but when I searched for the error, I see people saying, it was not able to overcome this error. So when you don't find a solution to your problem, always go vanilla.

Solution:

Add a Mask Helper in your project

export function MaskedDate(event: any) {
  var v = event.target.value;
  if (v.match(/^\d{2}$/) !== null) {
    event.target.value = v + '/';
  } else if (v.match(/^\d{2}\/\d{2}$/) !== null) {
    event.target.value = v + '/';
}
}

at your component:

import { MaskedDate } from './helpers/mask.helper';

Declare the property in your component:

  dateMask = MaskedDate;

In your component html:

 <input style="float:none"  (keyup)="dateMask($event)" formControlName="birth_date"  placeholder="Select a date"  ngx-mydatepicker [options]="myOptions" #dp="ngx-mydatepicker"/>

You can still use text-mask with other inputs, no problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.