2

I'm making an autofill to fill the values automatically.

I've this page using AngularJS. When I copy the mobile number using $("input[name='username']").val('9999999999') it does not cause change event be fired upon which "Get OTP" link should be activated.

Sometime back I has asked similar question : How to trigger click on a button

I've tried many ways like Is it possible to simulate key press events programmatically? but I'm not able to make it work.

I've also tried sending focus-in event, then simulated mouse click within it, then copying the value then simulating mouse click on a different element etc.

What could be the way to make it work?

Community
  • 1
  • 1
user5858
  • 1,082
  • 4
  • 39
  • 79

1 Answers1

0

This is your textChanged() function which is called initially and whenever text is changed:

a.textChanged = function() {
    a.isMobCollapse = "collapse", a.username && (a.errorMsg = "", a.user.otp = "", s(a.username) && 10 == a.username.length ? (a["continue"] = "enabled", 
    a.isEmailOrMobile = "mobile") : a["continue"] = "disabled");
}

Now this function doesn't check for value $("input[name='username']").val(), it checks for ng-model value 10 == a.username.length. That's why your jquery code has no effect.

Just transfer all the logic inside angular scope and instead of setting like this

$("input[name='username']").val('9999999999')

initialize angular model like this:

a.username = '9999999999';
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71