I need that once event1 triggers, it activates event2 and disable self, and vice versa. I'm having trouble with the last step, because when I focus out, the input only briefly disappears.
/**
* Actions to be done once one of the div is clicked.
* It should hide the span, fade in the input, focus it, disable the self event and enable the input event.
*/
$('.range-wrapper').click(e => rangeClickEvent(e.target));
/**
* Actions to be done once one of the input loses focus or the enter key is pressed.
* It should hide the input, fade in the span, reenable the click event on the wrapper and disable self.
*/
$('.range-wrapper input').on('focusout keyup', e => {
if (e.type == 'keyup' && e.keyCode != 13) {
return;
}
rangeFocusOutEvent(e.target);
$('.range-wrapper input').off('focusout keyup');
});
function rangeClickEvent(rangeElement) {
$(rangeElement).children('span').hide();
$(rangeElement).children('input').fadeIn(300).focus();
$(rangeElement).off('click').removeClass('clickable');
}
function rangeFocusOutEvent(inputElement) {
const parentDiv = $(inputElement).parent();
$(inputElement).hide();
$(parentDiv).children('span').fadeIn(300);
setClickEventBack(parentDiv);
}
function setClickEventBack(rangeElement) {
$(rangeElement).addClass('clickable');
//line below - re-adding the click event causes trouble
$(rangeElement).on('click', rangeClickEvent(rangeElement));
}
Here's what I have so far: https://jsfiddle.net/1j7fby49/12/
So basically clicking on the div hides the span and shows the input. Once I'm done with the input (focusout or enter key), it should hide the input and show the span again.
How can I achieve that?