mirror of
https://github.com/moodle/moodle.git
synced 2025-02-23 03:18:07 +01:00
The initial approach I took was to provide a noscript area containing the standard input element, and to move it to a hidden input element as part of the passwordunmask setup. This allowed behat tests to pass both with and without JS enabled (i.e. with Goutte and real browsers), and also ensured that the real input did not appear on screen. However, the standard formslib validation occurs before other page JS is run and hooks into the elements on page during its setup. Since noscript elements are not accessible to scripts as standard elements, the form validation would fail for _client_ side validation and work for server-side validation. This change creates creates the hidden input element in the template instead, as well as the password element in the noscript tag. Doing this means that when JS is disabled, the form has two elements of the same name - one hidden, and the second a visible password field. Since the latter element will always override the former one on form submission, and the noscript variant is last, the noscript variant wins when JS is disabled and tests continue to pass. When JS is enabled, the noscript variant is not a valid part of the DOM (the browser sees it as a hidden text field essentially). The password is not automatically entered into the hidden field, so the autocomplete prevention continues to work as expected.