How to write validation functions for jQuery mobile input type range? -
How to write validation functions for jQuery mobile input type range? -
following problem: have input fields of type range. jquery mobile automatically transforms them input field slider aside. want instant validation while typing. validation script shall remove non-digits. function utilize works on input field text not input type range.
this html:
<label for="my_range_input_field">label_text:</label> <input data-type="range" type="range" name="my_range_input_field" id="my_range_input_field" value="10000" min="0" max="85000" />
this jquery validation function:
$(document).delegate('#my_range_input_field', 'input', function(e) { $(this).val($(this).val().replace(/[^\d]/g, "")); });
the problem is, function deletes whole input value , not non digits. tried debug , when using console.log display val saw empty string when not digits typed in input field. did research , found following: how raw value <input type="number"> field?
so there pre-validation , seems can't retrieve value want because it's invalid , displays empty string. there still way value?
or there @ to the lowest degree :invalid
selector input fields of type range show user reddish background or something?
you can utilize general solution preventing input of alpha characters. not code cant find link credit person wrote code.
demo
https://jsfiddle.net/gv4xp4y7/
$(document).on("keydown", "input.ui-slider-input", function (e) { if ($.inarray(e.keycode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || (e.keycode == 65 && e.ctrlkey === true) || (e.keycode >= 35 && e.keycode <= 40)) { return; } if ((e.shiftkey || (e.keycode < 48 || e.keycode > 57)) && (e.keycode < 96 || e.keycode > 105)) { e.preventdefault(); }});
jquery jquery-mobile input range
Comments
Post a Comment