0

I am trying to fill a website with the help of a greasemonkey script. This website has some required fields and I can't submit the form when they are not filled in.

Now, I have the following problem:
I fill the required fields using jQuery's .val. When I now click the submit button - even manually with the mouse - then it says that some of the required fields are not filled in.
When I click in one of the affected fields with the mouse and then click the submit button again, it accepts the value and proceeds.

My question is:
How do I figure out which event the website listens to? Or:
How can I trigger the validation of the fields from my script?

Update: I tried the following command directly in Chrome's developer tools' console:

jQuery('#ext-comp-1080').click().focus().focusin()
                        .val('my value').change().blur().focusout()
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443

2 Answers2

1

Most often, the validation is tied to a blur event.

In jQuery, you would use:

$('#thingToBlur').blur();

That said -- I have never triggered events through a UserScript, so I'm not sure if they will correctly hit the element in unsafeWindow.

If you need to force-ably run JavaScript on the page (and that includes firing the events there), see this question:

UserScripts & Greasemonkey: calling a website's JavaScript functions

Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
  • Thanks, but this doesn't work. For simplicity's sake, I just open the page and start Chrome's developer tools for testing and enter my code directly in the console. Like this, I believe the problem mentioned in your link should not apply - am I correct? Anyway, because I tried these "obvious" events already, I asked if there is a way to figure out, what does trigger the validation on that particular website. – Daniel Hilgarth Aug 22 '14 at 06:18
  • If the common things don't trigger it, the only other real option is to read the source ... – Jeremy J Starcher Aug 22 '14 at 06:22
  • I updated my question with the code I am using. Maybe you see something obvious. Reading the code - I tried to do that, but there are no event handlers, they seem to get attached dynamically. I even tried to figure out the attached handlers at runtime, but no luck here either. Any idea where else to look? Or, is there a technique that allows me to log any change to the internal state (HTML or Javascript) of a website? – Daniel Hilgarth Aug 22 '14 at 06:26
0

Since after you change the file by using .val() and then you click into a field and click submit it most likely listens on change or blur event.

// set value
$(selector).val(value);

// trigger click
$(selector).click();

// trigger change or blur
$(selector).change();

You could also do method chaining if you wanted.

GGio
  • 7,563
  • 11
  • 44
  • 81