accessible-autocomplete icon indicating copy to clipboard operation
accessible-autocomplete copied to clipboard

On manually deleting the selected option the initial value is still submitted.

Open lukefisher10 opened this issue 8 years ago • 6 comments

Hi Team

When a user has selected an option from the autocomplete, if they press the delete key until the input field is blank and then submit the form, the initial value is submitted, as opposed to a blank field.

lukefisher10 avatar Jul 24 '17 10:07 lukefisher10

Yeah, this is a legit issue with the way the autocomplete works currently. Because it uses a select element underneath, unless that select element has a default option which doesn't pass validation, the user will always submit whatever is default for that select. You need to add custom validation to prevent this.

I've marked this as a bug as we should find a better way to communicate or work around this behaviour. This is a possible solution: https://github.com/alphagov/accessible-autocomplete/issues/198

tvararu avatar Jul 24 '17 13:07 tvararu

Also worth noting that this also applies when entering gibberish into the field, basically anything that doesn't match an option results in the previously selected option being submitted.

stevelacey avatar Jul 25 '17 09:07 stevelacey

My expectation is that whatever's entered in the field be submitted.

Where it's progressively enhanced from a select, this should be blank or an option - as we shouldn't allow users to leave text in the field that isn't an option.

Where it's an enhanced text box, we should leave whatever they type and submit it.

edwardhorsford avatar Jul 25 '17 14:07 edwardhorsford

This is a legitimate bug that needs fixing but it's also related to the wider discussion here: https://github.com/alphagov/accessible-autocomplete/issues/260

hannalaakso avatar Feb 21 '18 18:02 hannalaakso

After looking into this today I can see several scenarios for null values (including that in which a user deletes the previous selection in order to submit null), some of which are covered by existing documentation.

On considering proposed fixes it became clear that a solution will result in the implementation diverging between javascript-enabled and javascript-disabled implementations of the library.

The proposed solution I looked into was programmatically adding a null option when the field is non-mandatory. However, for this to match the javascript-disabled scenario, it requires a developer update to the html of the page to include a null option, resulting in a breaking change.

I've submitted a pull request to the README to warn developers that clearing the field does not clear the submitted value and to use showAllValues if they need a null option.

MatthewBurstein avatar Dec 17 '18 17:12 MatthewBurstein

I wonder if it would be hard to make the autocomplete swap out the select for an input when it initialises - ie don't use selects under the hood after initialisation - that way whatever the input visually contains is what gets submitted.

edwardhorsford avatar Aug 14 '19 10:08 edwardhorsford