I have an input set to type “number” that works fine but I also wanted users to be able to pull up a visual/onscreen numpad they could use to enter in a number by clicking the numbers rather than typing it on their keyboard. I want the visual numpad to enter the number into the input so it can be submitted in the same way regardless of it is typed out or enter via the visual one.
So, I made a numbpad on an off-canvas component and added buttons and put an on-click event that adds the clicked number to the input like this
(inp_number.value + “1”) and (inp_number.value + “2”) and so on. I believe the " " is necessary because otherwise it will act as a number and make 1+1=2 rather than 11 but would like some conformation this is the correct way to do it.
My issue is with getting the . to work. When I tried (inp_number.value + “.”) it seems to break the input, it sets it to the placeholder value and won’t let me enter in any numbers.
My other issue is that I’m not sure how I can get a backspace button to work. Essentially, I just want to delete the last character from the input ie 123 -> 12 but I don’t know how to go about doing that.
Has anyone else done anything like this or have any ideas on how to make this work?
For the decimal if I type it on my keyboard it works fine, its only when doing it via a button with (inp_number.value + “.”) that breaks it.
And thanks for the info on how to do the backspace, got that working.
Edit - Tried the decimal again and now it seems like when I put it in it breaks it but then when I add another number it fixes it. Like if I put in 150 its fine and then if I add the decimal it shows the placeholder 0.00 but then if I add a 1 it will work and show 150.1
Could it something like 150 and 150.1 are valid numbers but 150. isn’t? Would it need to be 150.0? But if I type it in myself it shows up if I type 150. so I’m not sure.
I tried adding step=".01" and it’s still the same problem.
If I use my physical keyboard to type into the input, I can type in 1 or 1. or 1.1 and it will show up fine.
If I use the on-screen keyboard to enter a number into the input via a dynamic event, I can put in 1 fine but if I put 1. it will only show the placeholder but if I add another 1 after it will show 1.1 fine.
I’m not sure it is. I think it is the implementation. Quite a different usage to the norm for form inputs. Have only seen this sort of thing done using JavaScript personally. Sorry I was of no help Eric.
That’s what I ended up doing. I found out it was giving this error
formElement.js:102
The specified value "1." cannot be parsed, or is out of range.
_setValue@formElement.js:102setValue@formElement.js:26Object.keys.forEach.data.<computed>@BaseComponent.js:463(anonymous)@parser.js:717t@parser.js:468(anonymous)@parser.js:459dmx.parse@parser.js:394(anonymous)@on.js:8a@events.js:280
it seems like the number input doesn’t consider 1. a valid number.
So I changed it into a text input and added some stuff so that it only accepts numbers and a decimal point, and I think it will all work fine.
If it’s in the dmxAppConnect folder I assume that means it’s from Wappler? @Teodor Should I make a bug report for this or can you guys just look through this thread? Or is it not something to even worry about? I did find a workaround.
When setting the value on a number input it will try to parse the string as a number and 1. throws an error here. This is an implementation of the browser and not something we can change.
Instead of using a number input use a standard text input.