简体   繁体   中英

How can I force an AngluarJS form to realize required fields have been filled through DOM manipulation (no user input)?

I've written an Excel VBA macro to paste some data into an AngularJS form -- it opens an Internet Explorer (11) window, navigates to the page containing the form, and crawls the document tree looking for certain elements by their ID, changing their values from blank to non-blank strings from the Excel sheet. However, when I submit the form, the form logic treats all the required fields as if they were still blank, drawing a red box around the supposed offending fields. (I can intervene at this point by clicking into each field, typing a random character at the end of the pasted data and immediately deleting it, and this triggers the logic that the required field is now filled.)

I'm not a javascript programmer and didn't design the form (nor can I change it in any way). I can manipulate the DOM elements (focusing and blurring the fields, for example, though that doesn't seem to work), and I can probably run any command that could be entered into the console in the browser debugger. Would any AngularJS expert know a relatively simple way to force the form to check itself?

Have you solved this problem Karim or found any solution? I recently had a project of mine, with the same problem. Try to find the tag with ng-submit something like what I have 'ng-submit"=submit($event)"'. I referenced the form element and used .submit. In your case, try this:

Set HTMLFormEl = HTML.getElementById("accountNameValue")

HTMLFormEl.Submit

The 'submit' was the one that solved my problem. Let me know if this works for you.

Not a VBA nor AngularJS expert but I noticed that AngularJS has nothing to do in treating the required fields as if they were still blank. Just need to find the correct event to trigger. Just my opinion.

Don't know is my answer is actual or not, but i had the same problem, and i found a solution using Application.SendKeys. The function filling out the form looks like this

Function inputWrite(ByVal str As String, inputEl As Object, ByVal hwnd As LongLong) As Boolean
TryAgain_inputWrite:
    strSub = Left(str, Len(str) - 1)
    strKey = Right(str, 1)

    inputEl.Focus
    inputEl.Value = strSub
    setToFore hwnd
    Application.SendKeys strKey

    Application.Wait DateAdd("s", 1, Now)

    If (inputEl.Value = str) Then
        inputWrite = True
    Else
        GoTo TryAgain_inputWrite
    End If
End Function

setToFore is just a function to always keep the Internet Explorer on top of other applications, so the send key won't miss.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM