0

When I enter your bid into the below input field, the below jquery code runs and updates the price breakup calculation. This code runs fine on desktop/tablet. But doesn't work on mobile browser (android/ios).

enter image description here

    $('[name="woof_treat"').on("change keyup keypress input", function(e){
      e = e || window.event;

      var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
      var charStr = String.fromCharCode(charCode);
      if (/\d/.test(charStr) || charCode=="8" || charCode=="46") {
        $('.cost-desc').removeClass('ptr-error');
        $('.error').addClass('d-none');
        priceBreakDown("substract");
          return true;
      }else{
        return false;
      }
  });

<input  class="" pattern="[0-9]" type="text" name="woof_treat" placeholder="<%= @woof.price%>" value="<%= @price || @woof.price %>"  <% if @user.fetches.where(woof_id: @woof.id).present? %> disabled <% end %>>
rarejewel
  • 26
  • 1
  • 4
  • "Mobile Browser" it means a webview inside an app or the regular browser such as chrome or safari? – Susana Santos Jun 15 '18 at 13:01
  • If it means a webview. once I had a similar problem, spent a huge amount of time debugging my code and it turns out javascript wasn't enabled inside the app. If it means the regular browser you can debug your code on the computer using google chrome device_mode. https://developers.google.com/web/tools/chrome-devtools/#device_mode – Susana Santos Jun 15 '18 at 13:10
  • 1
    Sorry, not device mode. Remote debugging. https://developers.google.com/web/tools/chrome-devtools/remote-debugging/ – Susana Santos Jun 15 '18 at 13:18
  • No I am talking about chrome/safari browser in android/ios – rarejewel Jun 15 '18 at 13:18
  • Thanks for telling me about remote debugging it was very helpful. Figured out the solution. In mobile browser, the e.keyCode was returning 229. So in mobile we need to use e.target.value instead of e.keyCode. REfer to this answer https://stackoverflow.com/questions/22473950/keypress-event-not-firing-in-android-mobile# – rarejewel Jun 15 '18 at 16:47

0 Answers0