Skip to content

If clicked and so options clear then does not trigger a change to empty if no option is then selected and user clicks off drop-down #9

@robinwilson16

Description

@robinwilson16

If an option is first selected and then the drop-down is clicked again but no option is selected then the datalist ends up empty but it does not trigger a change.

To change this I added this line under event handlers:

input.addEventListener('click', listClear);

Then I added this function at the end:

function listClear(e) {
   const input = target(e);

   let changeEvent = new Event(`change`);
   input.dispatchEvent(changeEvent);
   input.value = ``;
}

This sets the option to the blank choice and then clears the text from the field. Might not be useful depending on the scenario but for me if I didn't do this the underlying option still contained a choice whilst the datalist selector was empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions