0

Question

I have all the input masks set-up however I'm struggling to figure this one out logically..

So I have an input field for Gigabecquerels. However, as it currently stands the input could be like this 1,428.22Gbq, 428.22Gbq, 22.80Gbq So, how does one account for this? I could simply just place the gbq after the textfield has finished editing, however I would prefer to do it with an input mask, whilst also making it easy-to-use and not confusing.

    $("#gbq").mask("9,999.99Gbq");

Any help is greatly appreciated, thank you.

EDIT

Think of it like this,

Focused __________ (press period)

2236______ (press period)

period pressed

2,236.__Gbq

2,236.66Gbq

Danny123
  • 81
  • 1
  • 10
  • I know I'm already questioning logic by using something to give an absolute input that is required by making it variable. However, I'm curious as to whether it can be achieved without being a mess. – Danny123 May 04 '15 at 15:33
  • What's a sample output from `$("#gbq").val();` ? Or even better, could you post a quick sample JSFiddle of your input field with the mask setup? – rickcnagy May 04 '15 at 15:34
  • Do you want to allow the user to enter a plain number when the field has focus, but then display it in your format/mask when the field loses focus? – yas May 04 '15 at 15:34
  • @br1ckb0t The code is implemented over many files, however it displays as underscores and when you type it fills in the underscores and skipping symbols that are meant to be there. – Danny123 May 04 '15 at 15:40
  • @Danny123 I see. So `$("#gbq").val();` might return something like `1,5__Gbq`? – rickcnagy May 04 '15 at 15:41
  • @dave when focused it shows the input mask, and when you type it fills in the blanks/underscores. I'd prefer to change it as they type. So for instance they see it as `_,___.__Gbq` but if they type `4,42_.__Gbq` and press period it will turn to `426.__Gbq` – Danny123 May 04 '15 at 15:42
  • or have it so it is `______ ( press period )` then say `1425___ (press period)` turns to `1,425.__Gbq` – Danny123 May 04 '15 at 15:44
  • I see what you are trying to do ... but IMHO you are better off leaving it as a plain input field, and absorbing keystrokes that are not numerical or past 2 decimal points. When the field is not in focus, then format it for display. – yas May 04 '15 at 15:52
  • @dave I agree, I was just curious as to whether it can be achieved. – Danny123 May 04 '15 at 15:55

0 Answers0