1

Hi I have a select element where the last option is supposed to initiate a rest call to log out the user

Here is what i have tried so far

<select ref:logout>
    <option selected value={$user.role}>{$user.role}</option>
    {#each $user.pages as page}
        <option value={page}>{page}</option>
    {/each}
    <option on:click="logout()" value='logout'>Logout</option>
</select>

<script>
    export default {
      methods: {
        logout() {
          console.log("well hello");
      }
    };
</script>

The problem is that the logout method never gets called

Update The problem was that I was using click event instead of change and placed it on the option element instead of the select

Matti
  • 495
  • 6
  • 21

1 Answers1

0

Could you change it to be a onchange event on the select element? Then add an if statement to detect value=='logout'. Similar issue but without svelte: Click event on select option element in chrome

JasonWilson
  • 136
  • 7
  • I should have mentioned that i was looking for svelte events rather than dom events, as i currently don't include jQuery in this project. Guss ill just have to create a fake drop-down using buttons, since the select element was never intended for this purpose. – Matti Dec 19 '18 at 07:59
  • 1
    What about Then have a method doStuff(v){ if(v=='logout'){console.log('do it');} } – JasonWilson Dec 19 '18 at 14:14