Skip to content

value attribute set with jquery selector can't be changed via HtmlInput Element #422

@thuri

Description

@thuri

Hi, first of all thanks for all the work you've done on that project.

I may have found a bug or I am unaware of an mistake in my code.
To reproduce the issue I have setup a small test project: https://github.com/thuri/htmlunit-jquery-selector-init
It uses:

  • Java 11
  • JUnit 5
  • HTMLUnit 2.56.0

The html page of the project defines a small form with two fields, a text input and a datetime-local input. (But i actually don't think that the type has anything to do with the problem).

The page also contains a little javascript code that uses jquery to define an event handler for the ready event.
In that code I try to initialize the values of the inputs using the .val() function of jquery. This seems to work as i'm able to read the values with HTMLUnit.

  $("#textField").val("Initialised");
  $("#timestampField").val("2021-12-17T15:15");

After that the code registers an submit handler for the form that is only used to log the values and skip the actual sending of the form, as there isn't an actual backend to receive the values.

Within the unit test I try to override the values like this:

   form.getInputByName("textField").setValueAttribute("Foobar");
   form.getInputByName("timestampField").setValueAttribute("2021-12-31T12:00");

when the form is submitted the event handler is called as expected but the values set within the test are not available to the jquery handlers which can be seen in the console log.

And the values are also unchanged in the HtmlPage returned by the click handler which will make the junit test in the project fail.

If the initializing is done without jquery the submit Handler get's the correct values and the result HtmlPage also contains the correct values:

   document.forms.theform.textField = "Initialised";
   document.forms.theform.timestampField = "2021-12-17T15:15";

It would be great if you could have a look at this and probably tell me whether I've made a mistake or confirm that there is something strange happening here.

Thanks in advance,
Michael

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions