0

I think I just have a fundamental misunderstanding of how this works. I'm am trying to create a snippet that validates an input field's entry in real time. The input is inside a Bootstrap popover, and thus no usual forms of date validation are working for me. This will only be used on one device, a Kindle 7, on chrome. what I have so far is

        $('#datePicker').on('shown.bs.popover', function(){
            $('[name="start"], [name="end"]').on('input', function(e){

                if(e.key.search(/[0-9]|tab|enter|shift|control|alt/i) >= 0){
                    console.log("Good input:" + e.key);
                }else{
                    console.log("Bad input:" + e.key);
                    e.preventDefault();
                    e.stopPropagation();
                }
            });

            $('[name="start"], [name="end"]').on('keyup',function(){

                if(this.value.length == 2 || this.value.length == 5){
                    this.value = this.value + "-";
                }
            });
        });

My thinking being that the event "input" holds some data about what happened. Through all of my searching though, I have found no such data. I was using "keydown" instead, and it did work perfectly, except that the Kindle's virtual keyboard only returned undefined values, and that's when I was saw someone suggest using "input" instead.

Could someone please let me know what I'm doing wrong

Geoffrey H.
  • 160
  • 2
  • 17
  • Are you actually using `\$` in your code? As that will be causing at least one error. – Rory McCrossan Jul 27 '17 at 20:21
  • Sorry, will edit. I'm doing all this through Perl. – Geoffrey H. Jul 27 '17 at 20:22
  • Creating bindings inside another binding is a code smell personally. The chance exists for duplicate bindings. <-- side note – Taplar Jul 27 '17 at 20:26
  • Also to note, that an 'input' event should only emit from events that resulted in the value of the input to change. So your key search for things like shift, control, alt; those would never be the case. – Taplar Jul 27 '17 at 20:28
  • Thank you, I'll keep that in mind. And the regex was there from when I was using "keydown". I'll be to sure to get rid of it. – Geoffrey H. Jul 27 '17 at 20:38

0 Answers0