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

p-inputMask doesn't clean itself when model value is set to "undefined" #937

Closed
rafaelodon opened this issue Sep 21, 2016 · 2 comments
Closed
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@rafaelodon
Copy link

rafaelodon commented Sep 21, 2016

There's this p-inputMask two-way binded to a "number" variable via [(ngModel)]. If this variable is set to "undefined" by some event, I expect to see this input empty. But the inputmask keeps displaying the last value.

I managed to hack a solution by copying the InputMask code to my project and intercepting the get/set of the component value, thus changing it's display value to '' when 'undefined' is informed in this property setter:

...
export class InputMask implements AfterViewInit,OnDestroy,ControlValueAccessor {
    ...
    /* BEGIN - Fix for setting undefined value on input-mask*/        
    innerValue:any; //rename 'value' property to 'innerValue' and use it within get/set value

    get value(): any {        
        return this.innerValue;
    };

    set value(v: any) {            
        if (v !== this.getUnmasekd) {
            if(v == undefined){
                this.el.nativeElement.children[0].value = "";
                this.innerValue = undefined;
            }else{
                //maybe there's more things to care about here... (store unmasked ou masked value?)
                this.innerValue = v;
            }
            this.onModelChange(v);
        }
    }
    /* END - Fix for setting undefined value on input-mask*/
}

It worked for my case, but I don't think it's the best solution.

I'm using: angular "2.0.0", primeng": "1.0.0-beta.16", "jquery": "2.2.4", "jquery.inputmask": "3.3.3".

@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Sep 27, 2016
@cagataycivici cagataycivici added this to the 1.0.0-beta.17 milestone Sep 27, 2016
@cagataycivici cagataycivici self-assigned this Sep 27, 2016
@cagataycivici
Copy link
Member

cagataycivici commented Sep 27, 2016

Mask is reimplemented as a native component instead of jquery, so will check this for beta17.

@gilsondev
Copy link

This still ocorring in PrimeNG 1.1.4, with properties this value:

clear(event) {
  this.inputTest = "";
}

Something undefined and null works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants