Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Statement Initial Value Not Working #3060

Closed
stevesob opened this issue Jun 20, 2019 · 1 comment
Closed

Select Statement Initial Value Not Working #3060

stevesob opened this issue Jun 20, 2019 · 1 comment

Comments

@stevesob
Copy link

stevesob commented Jun 20, 2019

I am using the "select" statement to create a control and it works great with bind:value except that I can't seem to set an initial value.

Here is the control, when calling from the parent I need the select to be on the selected option, and it always selects the first option.

<script>
  export let selected
  export let label = ''
  let colors = [
    'w3-red',
    'w3-pink',
    'w3-purple',
    'w3-deep-purple',
    'w3-indigo',
    'w3-blue',
    'w3-light-blue',
    'w3-cyan',
  ]
</script>

<p>
  <span class="w3-text-grey w3-margin-right">{label}</span>
  selected={selected}
  <select class="w3-select {selected}" bind:value={selected}>
    {#each colors as color (color)}
      <option class={color}>{color}</option>
    {/each}
  </select>

</p>

Parent calling

<script>
 import W3selectcolor from '../components/ui/W3selectcolor.svelte'
 let selected = 'blue'
</script>
<W3selectcolor label="Select Color:" bind:selected />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants