Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

If a listener nods his head when you're explaining your program, wake him up.


devel / comp.lang.javascript / filling form automatically with a bookmarklet does not trigger validation of fields

SubjectAuthor
* filling form automatically with a bookmarklet does not trigger validation of fieAlfred
`* Re: filling form automatically with a bookmarklet does not trigger validation ofJJ
 `* Re: filling form automatically with a bookmarklet does not trigger validation ofAlfred
  `- Re: filling form automatically with a bookmarklet does not trigger validation ofAlfred

1
filling form automatically with a bookmarklet does not trigger validation of fields

<O-GdnaoT7PkfJ5_8nZ2dnUU78U_NnZ2d@brightview.co.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17200&group=comp.lang.javascript#17200

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 29 Jul 2021 09:26:10 -0500
From: invalid@invalid.invalid (Alfred)
Subject: filling form automatically with a bookmarklet does not trigger validation of fields
Newsgroups: comp.lang.javascript
Message-ID: <O-GdnaoT7PkfJ5_8nZ2dnUU78U_NnZ2d@brightview.co.uk>
Date: Thu, 29 Jul 2021 09:26:10 -0500
Lines: 42
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-3OKHXZAPCQcwVPufQoRjm38XSNE4HSduXKr7jvH9223hTdIdQfwVsPJZHUe+ccQmxsGGoaGsjL5TGpF!Mvz5q9TBuW2T7zL+YCI/dHgRMW2UCQWM8TOLGRzd5fVO6p6HwXLUhtFdWiliFij+1EcsZb+8F/F7!W0nTNBqm8Apy1WzSOoTWtB0wV4Tl
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2443
 by: Alfred - Thu, 29 Jul 2021 14:26 UTC

I am filling a form automatically with a bookmarklet, but I fail to
trigger the validation of the fields. The code is

// fill form field
var my_username="user123";
document.getElementsByClassName("form-field")[0].firstChild.value=my_username;
// simulate click on the submit button
document.getElementsByClassName("form-field")[1].firstChild.click();

When I use the bookamarklet "user123" appears on the screen. The
problem is that this does not trigger the automatic validation that
would be triggered by real keypresses. With real keypresesses the
field gets validated, a tick appears in the screen and the submit
button gets enabled.

Any idea on how to trigger the validadtion and enable click on the
submit button?

The relevant HTML code for the form fields:

<div class="form-field">
<input aria-label="Username" autocomplete="off"
class="form-control ng-dirty ng-invalid ng-touched"
maxlength="40" minlength="6" name="username"
pattern="^(?=.*[a-zA-Z0-9]{1,})[a-zA-Z0-9_@.-]*$"
placeholder="Username" required="" type="text">
</div>

The relevant HTML code for the submit button:

<div class="row button-group mb-30">
<div class="form-field">
<div class="col-md-6 col-12 form-button"></div>
<div class="col-md-6 col-12 form-button">
<button class="btn btn-next float-right" type="submit"
disabled="disabled">
<span>Continue</span>
<span aria-hidden="true" class="material-icons">chevron_right</span>
</button>
</div>
</div>
</div>

Re: filling form automatically with a bookmarklet does not trigger validation of fields

<19qaff5meems5.1o4ypnacyb7cc.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17201&group=comp.lang.javascript#17201

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!9uo04EpFeBk5Y+LbefdByw.user.46.165.242.91.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.lang.javascript
Subject: Re: filling form automatically with a bookmarklet does not trigger validation of fields
Date: Thu, 29 Jul 2021 23:06:56 +0700
Organization: Aioe.org NNTP Server
Message-ID: <19qaff5meems5.1o4ypnacyb7cc.dlg@40tude.net>
References: <O-GdnaoT7PkfJ5_8nZ2dnUU78U_NnZ2d@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="24584"; posting-host="9uo04EpFeBk5Y+LbefdByw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: 40tude_Dialog/2.0.15.84
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Notice: Filtered by postfilter v. 0.9.2
 by: JJ - Thu, 29 Jul 2021 16:06 UTC

On Thu, 29 Jul 2021 09:26:10 -0500, Alfred wrote:
> I am filling a form automatically with a bookmarklet, but I fail to
> trigger the validation of the fields. The code is
>
> // fill form field
> var my_username="user123";
> document.getElementsByClassName("form-field")[0].firstChild.value=my_username;
> // simulate click on the submit button
> document.getElementsByClassName("form-field")[1].firstChild.click();
>
> When I use the bookamarklet "user123" appears on the screen. The
> problem is that this does not trigger the automatic validation that
> would be triggered by real keypresses. With real keypresesses the
> field gets validated, a tick appears in the screen and the submit
> button gets enabled.
>
> Any idea on how to trigger the validadtion and enable click on the
> submit button?

HTML alone can not enable a disabled submit button, or disabled an enabled
one. Only JavaScript can do that. Meaning that the validation is done by
JavaScript. By an event handler code.

With some luck, bypassing the validation script and calling the form's
`submit()` may be sufficient enough if all form field values are already
valid. Or, manually enable the submit button, then call its `click()`
method. This will never work if the script does form data processing rather
than just form validation.

Since the script is triggered when a key is pressed, the event would be
either `input`, `keypress`, or `keydown`. If it's `input`, it can be
simulated by dispatching a newly created `input` event on the form field.

Otherwise it'll be difficult or may not be possible at all, since web
browsers do not allow keyboard input events to be simulated. What can be
done is to call the event handler directly. Assuming that the handler
function is accessible from the global context, and it does not check the
`isTrusted` property of the event.

Re: filling form automatically with a bookmarklet does not trigger validation of fields

<tsWdnXNn8Lak55H8nZ2dnUU78R_NnZ2d@brightview.co.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17203&group=comp.lang.javascript#17203

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 05 Aug 2021 18:54:33 -0500
From: invalid@invalid.invalid (Alfred)
Subject: Re: filling form automatically with a bookmarklet does not trigger validation of fields
Newsgroups: comp.lang.javascript
References: <O-GdnaoT7PkfJ5_8nZ2dnUU78U_NnZ2d@brightview.co.uk> <19qaff5meems5.1o4ypnacyb7cc.dlg@40tude.net>
Message-ID: <tsWdnXNn8Lak55H8nZ2dnUU78R_NnZ2d@brightview.co.uk>
Date: Thu, 05 Aug 2021 18:54:33 -0500
Lines: 80
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-kK39wRTNXcCbHxMNhZegFHcVzBsPmpW3Q4zEs+LLnNRyIzoRVbuGEAouIbJs6IdvM1tgcTucQGGpuxH!xtYOj5vnI2F8xUd2E5O5+8ykz+EvXWaqZX4o7+gN76Wvgr/RDTO8bjy1MNsPH4FzQESoXAtjjESK!DnRnPSLpEsvubTFpJGRsW7dXdYMQ
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 4950
 by: Alfred - Thu, 5 Aug 2021 23:54 UTC

JJ <jj4public@gmail.com> wrote:
> On Thu, 29 Jul 2021 09:26:10 -0500, Alfred wrote:
>> I am filling a form automatically with a bookmarklet, but I fail to
>> trigger the validation of the fields. The code is
>>
>> // fill form field
>> var my_username="user123";
>> document.getElementsByClassName("form-field")[0].firstChild.value=my_username;
>> // simulate click on the submit button
>> document.getElementsByClassName("form-field")[1].firstChild.click();
>>
>> When I use the bookamarklet "user123" appears on the screen. The
>> problem is that this does not trigger the automatic validation that
>> would be triggered by real keypresses. With real keypresesses the
>> field gets validated, a tick appears in the screen and the submit
>> button gets enabled.
>>
>> Any idea on how to trigger the validadtion and enable click on the
>> submit button?
>
> HTML alone can not enable a disabled submit button, or disabled an enabled
> one. Only JavaScript can do that. Meaning that the validation is done by
> JavaScript. By an event handler code.
>
> With some luck, bypassing the validation script and calling the form's
> `submit()` may be sufficient enough if all form field values are already
> valid. Or, manually enable the submit button, then call its `click()`
> method. This will never work if the script does form data processing rather
> than just form validation.
>
> Since the script is triggered when a key is pressed, the event would be
> either `input`, `keypress`, or `keydown`. If it's `input`, it can be
> simulated by dispatching a newly created `input` event on the form field.
>
> Otherwise it'll be difficult or may not be possible at all, since web
> browsers do not allow keyboard input events to be simulated. What can be
> done is to call the event handler directly. Assuming that the handler
> function is accessible from the global context, and it does not check the
> `isTrusted` property of the event.

Thanks very muhc for the suggestions which have shown me the way.
I have had a partial success.

I tried enabling the submit button manually with this code

document.getElementsByClassName("btn")[6].disabled=false;
document.getElementsByClassName("btn")[6].firstChild.click();

which in fact enabled the button and clicked it, but the form
submision failed due to the fields non being validated. On clicking
the button all the forms get highlighted in red.

So I have to validate each field with an input event. I have a
partial success. The first field gets validated and a tick appears at
its side. The second field does not get validated, despite having set
the right value.

var my_input_event = new Event('input', {
bubbles: true,
cancelable: true,
});

document.getElementsByClassName("form-field")[0].firstChild.value = "my_username";
document.getElementsByClassName("form-field")[0].firstChild.dispatchEvent(my_input_event);

document.getElementsByClassName("form-field")[1].firstChild.value = "abcd1234";
document.getElementsByClassName("form-field")[1].firstChild.dispatchEvent(my_input_event);

The HTML code for the two fields is very similar and I don't
understand why first one gets validated while the second not.

>> document.getElementsByClassName("form-field")[0].innerHTML
"<input aria-label="Username" autocomplete="off" class="form-control ng-dirty ng-touched ng-valid" maxlength="40" minlength="6" name="username" pattern="^(?=.*[a-zA-Z0-9]{1,})[a-zA-Z0-9_@.-]*$" placeholder="Username" required="" type="text">"

>> document.getElementsByClassName("form-field")[1].innerHTML
"<input aria-label="Password" class="form-control ng-untouched ng-dirty ng-valid" id="password" maxlength="20" minlength="8" name="password" placeholder="Password" required="" type="password">"

Any suggestion for validating the second field? should I use another
type of event? Maybe emulating keyboard input?

Re: filling form automatically with a bookmarklet does not trigger validation of fields

<a56dnYIo8ssWTpD8nZ2dnUU78dPNnZ2d@brightview.co.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17216&group=comp.lang.javascript#17216

  copy link   Newsgroups: comp.lang.javascript
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 06 Aug 2021 19:27:55 -0500
From: invalid@invalid.invalid (Alfred)
Subject: Re: filling form automatically with a bookmarklet does not trigger validation of fields
Newsgroups: comp.lang.javascript
References: <O-GdnaoT7PkfJ5_8nZ2dnUU78U_NnZ2d@brightview.co.uk> <19qaff5meems5.1o4ypnacyb7cc.dlg@40tude.net> <tsWdnXNn8Lak55H8nZ2dnUU78R_NnZ2d@brightview.co.uk>
Message-ID: <a56dnYIo8ssWTpD8nZ2dnUU78dPNnZ2d@brightview.co.uk>
Date: Fri, 06 Aug 2021 19:27:55 -0500
Lines: 11
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-HyIkVzJkBMts+gJgz6ZpOhdr5vzNh4sEX1z5qY9Ta49I3QOtq0Kt2QT8103TIrRMepiuumoUdJ61NGP!85EC2HkuBSpHJnjZ53zP5266stZJeYUJBcz6AVOMVhwBlN8bPD73Cy4K+TbhW/LBGyirP07ajUuH!2p6DjpFaE59oBuyiZyuPbYOUbSXp
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1484
 by: Alfred - Sat, 7 Aug 2021 00:27 UTC

Alfred <invalid@invalid.invalid> wrote:
> Any suggestion for validating the second field? should I use another
> type of event? Maybe emulating keyboard input?

I have solved it myself at the end. It turns out that a 'blur' event
is enough to validate all fields.

var my_blur_event = new Event('blur');
document.getElementsByClassName("form-field")[0].firstChild.dispatchEvent(my_blur_event);

Many thanks to JJ for showing me the path.


devel / comp.lang.javascript / filling form automatically with a bookmarklet does not trigger validation of fields

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor