core icon indicating copy to clipboard operation
core copied to clipboard

value.slice() is not a function when prefilled with number

Open RANSoftRA opened this issue 6 years ago • 11 comments

I am running into an issue when the value of the field is pre-filled with a number (bound with ngModel). Seems like the code is expecting a string as a value - hence the problem when the input value is a number (the slice function is not available).

image

Error occurs on line 7115 in ngx-material-keyboard-core.js:

    MatKeyboardKeyComponent.prototype.onClick = function (event) {
        ....        
        var value = this.inputValue; // value is a number
        ....
        if (char && this.input) {
            this.inputValue = [value.slice(0, caret), char, value.slice(caret)].join(''); // error here
            this._setCursorPosition(caret + 1);
        }
    };

RANSoftRA avatar Mar 08 '18 15:03 RANSoftRA

Looks like a simple string cast is missing.

davidenke avatar Mar 08 '18 15:03 davidenke

seems like it.

RANSoftRA avatar Mar 08 '18 15:03 RANSoftRA

i've solved this issue and fix a problem with the backspace, how can i pull request? (im new on GitHub)

ydock1 avatar Mar 08 '18 15:03 ydock1

@ydock1 Thanks for your afford! This article may help you: https://help.github.com/articles/creating-a-pull-request-from-a-fork/

RANSoftRA avatar Mar 08 '18 15:03 RANSoftRA

#51 i think is ready,

ydock1 avatar Mar 08 '18 15:03 ydock1

@davidenke just wanted to ask when we can expect a new relase which includes the provided bugfix? Just asking, becuause I would need this feature by the end of the month. Cheers

RANSoftRA avatar Mar 09 '18 15:03 RANSoftRA

@RANSoftRA you can "fix" without wait a new release. go to "/node_modules/@ngx-material-keyboard/core/esm5/ngx-material-keyboard-core.js" and go to the line "7083" (or this function MatKeyboardKeyComponent.prototype.onClick = function (event) )

and change this 3 lines 1- var value = this.inputValue == null ? "" : this.inputValue;

image

2-

this.inputValue = [value.slice(0, caret - 1)].join(''); image

3-

this.inputValue = caret ? [value.slice(0, caret), char, value.slice(caret)].join('') : value + char; image

The only problem with this is that if you make "npm install" you have to modify the file again

ydock1 avatar Mar 09 '18 15:03 ydock1

@ydock1 thanks for the quick reply.

I know that I could temporarily change the code under node_modules to make a quick fix. I simply asked if the fix will be present any time soon - otherwise I'll probably have to apply your suggestion.

thanks

RANSoftRA avatar Mar 09 '18 15:03 RANSoftRA

Does anyone have an estimate on when this fix will be released?

spyter avatar Sep 04 '18 14:09 spyter

I forked this repo, fixed this error and upgraded it to Angular 7. It can be found on npm as ngx7-material-keyboard. Simply install it by doing >npm i --save ngx7-material-keyboard and change import statements from @ngx-material-keyboard/core to ngx7-material-keyboard.

joskwanten avatar Dec 20 '18 10:12 joskwanten

Has this been upgraded for Angular 7

I have tried to use ngx7-material-keyboard but having many dependency issues.

Anyone else had luck with this?

hussainmaz avatar May 27 '19 11:05 hussainmaz