# Action handler with option \`:once\` alternative

**URL:** https://discuss.hotwired.dev/t/action-handler-with-option-once-alternative/4891
**Category:** General
**Created:** [March 19, 2023, 3:03pm UTC](https://discuss.hotwired.dev/t/action-handler-with-option-once-alternative/4891 "2023-03-19T15:03:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![adas172002](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/adas172002/32/2350_2.png) [@adas172002](https://discuss.hotwired.dev/u/adas172002)
#### Post date: [March 19, 2023, 3:03pm UTC](https://discuss.hotwired.dev/t/action-handler-with-option-once-alternative/4891/1 "2023-03-19T15:03:55Z")

</div>

Hi all,

I am trying to implement a conditional remove of event handler inside a stimulus action, similar to known pattern described [here](https://www.educative.io/answers/how-to-ensure-an-event-listener-is-only-fired-once-in-javascript). I am aware of possible solution with action option `:once`, hovewer I want to be able to keep event handler created by stimulus with the action code, depending on a test performed inside the action handler. Pseudo code of the action:

```auto
actionHandler(event) {
  if (event.target.value == "required") {
    // do something and
    event.target.removeEventListener(event.type, actionHandler);
  } else {
  // do something else, but don't remove event listener
  }
}

```

My code is not removing the event listener. To be honest I do not see it on the Event Listeners tab of dev console for the element with the action.  
Do you think I am on a dead end with this? Any ideas for other implementations?
