0

Here is the following code;

<div class="col-xs-12 col-sm-9">        
  <input id="Shipping_FirstName" name="firstname" ng-model="userOrder.Shipping.FirstName" type="text" class="form-control nsg-form--input ng-pristine ng-untouched ng-invalid ng-invalid-required ng-valid-maxlength" ng-class="{'is-invalid': shipping_subform.$submitted &amp;&amp; shipping_subform.firstname.$invalid}" required="" maxlength="35" tooltip="Please enter your first name" tooltip-toggle="shipping_subform.$submitted===true &amp;&amp; shipping_subform.firstname.$invalid===true" esw-google-analytics-blur="">        <!-- ngIf: shipping_subform.$submitted && shipping_subform.firstname.$invalid -->    
</div>

I have tried the following which writes the text to the input field;

document.getElementById("Shipping_FirstName").value = "test"
document.querySelector("input[id='Shipping_FirstName']").value = "test";

However, when I press the submit button, it says "Please enter your first name" as if the code above actually didn't write the text.

How can I fix this?

Thanks for any help, it's all appreciated.

5
  • why arent you using the ng-model Commented Mar 23, 2019 at 3:23
  • stackoverflow.com/questions/22942509/… Commented Mar 23, 2019 at 3:25
  • I am new to javascript and modern dom/jquery. What is ng-model and it's importance? Commented Mar 23, 2019 at 3:26
  • It is angular.... What you are doing is not the angular way Commented Mar 23, 2019 at 3:26
  • damm I am not sure if angular is going to work with the function evaluateJavascript in swift. Commented Mar 23, 2019 at 3:28

1 Answer 1

-2

Thanks to epascarello, the answer is;

var e = document.getElementById("Shipping_FirstName");
e.value = "test";
var $e = angular.element(e);
$e.triggerHandler('input');
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.