Ashish Shah Ashish Shah - 1 month ago 6
Android Question

Unable to enter value only in android device

I am running a website which is responsive. In that, I am facing a weird issue. Like if I enter value in a text box it allows me to enter in all platforms and browsers except android device (Tried in Samsung A3/A5).

FYI, I am using keypress event for this text field. But I am aborting ajax if the request is already been sent. This works fine but facing issue in android. Steps like below:

Steps:


  1. Remove already entered (at time of page load) value

  2. Try to enter "1"

  3. It shows original value which I have already removed instead of value as "1".



Can you please help me in this?

Update:
Below is the code:

Normal Input box of html.

<input type="text" class="col-lg-11 pad0 width80 infina_price input_price infina_txt_field size-ms-height formatNum" name="purchasePrice" id="purchasePrice" value="270.000" style="text-align: right;" /> €


j query

var ajaxReq = null;
$('.infina_price').unbind('keyup').keyup(function(e) {
if (ajaxReq != null) ajaxReq.abort();
var that = $(this);
ajaxReq = $.ajax({
type: 'get',
dataType: 'json',
data: 'purp=' + $(this).closest('.infinia').find('#purchasePrice').val() + '&ownr=' + $(this).closest('.infinia').find('#ownResource').val(),
url: "{{ path('fincalc_api') }}",
success: function (data) {
that.closest('.infinia').find('#infinaRate').val(data.infinaRate);
that.closest('.infinia').find('#infinaInterestRate').html(data.interestRate + '%');
}
});
return false;
});


UPDATE:
I found out that if I turn of the android predictive text, then I can enter values. But this is not the proper solution as I can to ask my all clients (users) to turn their android predictive feature off just to use one of the functionalities I provide in my website. Need a proper and convenient solution.

Answer

I found out the solution. It was the issue of priceFormat library.

the code was as below:

<script type="text/javascript">
(function(e){e.fn.priceFormat=function(t){var n={prefix:"",suffix:"",centsSeparator:".",thousandsSeparator:",",limit:false,centsLimit:0,clearPrefix:false,clearSufix:false,allowNegative:false,insertPlusSign:false,clearOnEmpty:false};var t=e.extend(n,t);return this.each(function(){function m(e){if(n.is("input"))n.val(e);else n.html(e)}function g(){if(n.is("input"))r=n.val();else r=n.html();return r}function y(e){var t="";for(var n=0;n<e.length;n++){char_=e.charAt(n);if(t.length==0&&char_==0)char_=false;if(char_&&char_.match(i)){if(f){if(t.length<f)t=t+char_}else{t=t+char_}}}return t}function b(e){while(e.length<l+1)e="0"+e;return e}function w(t,n){if(!n&&(t===""||t==w("0",true))&&v)return"";var r=b(y(t));var i="";var f=0;if(l==0){u="";c=""}var c=r.substr(r.length-l,l);var h=r.substr(0,r.length-l);r=l==0?h:h+u+c;if(a||e.trim(a)!=""){for(var m=h.length;m>0;m--){char_=h.substr(m-1,1);f++;if(f%3==0)char_=a+char_;i=char_+i}if(i.substr(0,1)==a)i=i.substring(1,i.length);r=l==0?i:i+u+c}if(p&&(h!=0||c!=0)){if(t.indexOf("-")!=-1&&t.indexOf("+")<t.indexOf("-")){r="-"+r}else{if(!d)r=""+r;else r="+"+r}}if(s)r=s+r;if(o)r=r+o;return r}function E(e){var t=e.keyCode?e.keyCode:e.which;var n=String.fromCharCode(t);var i=false;var s=r;var o=w(s+n);if(t>=48&&t<=57||t>=96&&t<=105)i=true;if(t==8)i=true;if(t==9)i=true;if(t==13)i=true;if(t==46)i=true;if(t==37)i=true;if(t==39)i=true;if(p&&(t==189||t==109||t==173))i=true;if(d&&(t==187||t==107||t==61))i=true;if(!i){e.preventDefault();e.stopPropagation();if(s!=o)m(o)}}function S(){var e=g();var t=w(e);if(e!=t)m(t);if(parseFloat(e)==0&&v)m("")}function x(){n.val(s+g())}function T(){n.val(g()+o)}function N(){if(e.trim(s)!=""&&c){var t=g().split(s);m(t[1])}}function C(){if(e.trim(o)!=""&&h){var t=g().split(o);m(t[0])}}var n=e(this);var r="";var i=/[0-9]/;if(n.is("input"))r=n.val();else r=n.html();var s=t.prefix;var o=t.suffix;var u=t.centsSeparator;var a=t.thousandsSeparator;var f=t.limit;var l=t.centsLimit;var c=t.clearPrefix;var h=t.clearSuffix;var p=t.allowNegative;var d=t.insertPlusSign;var v=t.clearOnEmpty;if(d)p=true;n.on("keydown.price_format",E);n.on("keyup.price_format",S);n.on("focusout.price_format",S);if(c){n.on("focusout.price_format",function(){N()});n.on("focusin.price_format",function(){x()})}if(h){n.on("focusout.price_format",function(){C()});n.on("focusin.price_format",function(){T()})}if(g().length>0){S();N();C()}})};e.fn.unpriceFormat=function(){return e(this).off(".price_format")};e.fn.unmask=function(){var t;var n="";if(e(this).is("input"))t=e(this).val();else t=e(this).html();for(var r in t){if(!isNaN(t[r])||t[r]=="-")n+=t[r]}return n}})(jQuery);

$('.formatNum').priceFormat({
        thousandsSeparator: '.',
        centsSeparator: ','

    });

because of this class, this issue was happened.

I removed '.formatNum' class to resolve this issue. But I lost the functionality of this library. It would be great if anyone can help me using this library and don't let this issue come again.

Comments