简体   繁体   English

input type=number 无法在手机上插入负数

[英]input type=number not possible to insert negative numbers on mobile phone

I'm testing my app on my mobile phone (samsung galaxy note II with chrome) and I have a problem with the numeric input fields.我正在我的手机(带 chrome 的三星 Galaxy Note II)上测试我的应用程序,但我在输入数字字段时遇到了问题。

In my app these fields can accept negative numbers, and on the browser it's all fine as I have the - button and also the arrow sliders (from html5) for choosing the number.在我的应用程序中,这些字段可以接受负数,而在浏览器上这一切都很好,因为我有-按钮和用于选择数字的箭头滑块(来自 html5)。

On the phone though the sliders are not rendered, and the browser recognise the input type=number, and just renders a simplified numeric keyboard, which doesn't contain the - sign, so I didn't see a way to insert the negative number I wish.在手机上虽然没有呈现滑块,但浏览器识别输入类型=数字,并且只呈现一个简化的数字键盘,其中不包含-符号,所以我没有看到插入负数的方法我希望。

My app uses twitter bootstrap 2.3.2 with jquery, I'm not sure how to solve this problem.我的应用程序使用带有 jquery 的 twitter bootstrap 2.3.2,我不知道如何解决这个问题。

here's the code for one of my input fields that work fine on my computer, but can't use them properly on my phone:这是我的一个输入字段的代码,它可以在我的计算机上正常工作,但无法在我的手机上正确使用它们:

<input class="input-mini" data-type="distance_price" id="distance" label="false" name="distance" step="0.1" type="number" max="-0.1">

我手机的截图

in the image you can see how the field in red is marked as wrong because it needs to be negative, but my keyboard doesn't let me insert symbols.在图像中,您可以看到红色字段如何标记为错误,因为它需要为负数,但我的键盘不允许我插入符号。 including the - sign.包括-符号。 any clue?任何线索?

The issue is specific to Samsung custom keyboard - hooray to vendors who think they're smarter than everyone.这个问题是三星定制键盘特有的——对于那些认为自己比所有人都聪明的供应商来说,万岁。 Here is another example of this issue at work这是工作中此问题的另一个示例

In short, there's no way to make the minus sign show up on Samsung Android numeric inputs.简而言之,没有办法让减号出现在三星安卓数字输入上。 Here are a few workarounds I've run across:以下是我遇到的一些解决方法:

1) Google Keyboard 1) 谷歌键盘

The user can install a different keyboard (like Google Keyboard ).用户可以安装不同的键盘(如Google 键盘)。 Obviously not ideal to have people install something though.显然,让人们安装一些东西并不理想。

在此处输入图片说明

2) Negate Button 2) 否定按钮

As @Cris already suggested, add a button which will negate the value.正如@Cris 已经建议的那样,添加一个取消该值的按钮。 If you've got the screen real estate then great.如果你有屏幕空间那就太好了。

3) Double Dot Trick 3)双点技巧

We ended up with a fairly ugly workaround where the user can press .我们最终得到了一个相当丑陋的解决方法,用户可以按. twice and it will negate the number.两次,它将否定该数字。 Totally non-discoverable but an extra button wasn't an option for us.完全无法发现,但我们无法选择额外的按钮。

https://gist.github.com/bendytree/936f6b9b4c0e10138b7e9158b5fd05d9 https://gist.github.com/bendytree/936f6b9b4c0e10138b7e9158b5fd05d9

Make an extra input field.创建一个额外的输入字段。 A "sign" checkbox, selecting natural or negative integers. “符号”复选框,选择自然或负整数。

Then hook the onchange event of the checkbox so that you update the number view to reflect the chosen sign.然后挂钩复选框的 onchange 事件,以便更新数字视图以反映所选符号。

如果您使用 value 属性 (value="-0.1") 加载初始负值,那么您将为您预加载减号。

<input class="input-mini" data-type="distance_price" id="distance" label="false" name="distance" step="0.1" type="number" max="-0.1" value="-1">

If you returned here because the Double Dot Trick from above stopped working... It seems an update to how input type="number" fields are handled keeps the second "dot" from even registering as a keystroke stopping the Double Dot from working.如果你返回这里是因为上面的双点技巧停止工作......似乎对输入类型=“数字”字段的处理方式的更新可以防止第二个“点”甚至注册为停止双点工作的击键。 In my case, I changed the test line in the JS to就我而言,我将 JS 中的测试行更改为

if (lastkey === "." && (key === "." || e.originalEvent.inputType == "deleteContentBackward")){

to create the equally hacky "Dot Backspace Trick"创建同样hacky的“Dot Backspace Trick”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM