Question

How to clear easyui combobox input on click? Looked for onClick event on editor but didn't find. Tried to bind event on input class but didn't work.

Was it helpful?

Solution

The combo box isn't created until after the DOM is rendered, so you have to use event delegation to target its focus and blur events

$("body").on("focus", "input.combo-text", function(){
    $(this).data("prev-value", this.value);
    this.value = "";
})
.on("blur", "input.combo-text", function(){
    if ($(this).val() === ""){
        $(this).val($(this).data("prev-value"));
    }
    $(this).data("prev-value", "");
});

As you can see, when the input receives focus, we are storing the previous value as a data attribute on the element, then retrieving it when focus is lost if the user didn't input anything different.

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top