Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
How to test svelte input attribute agains multiple options

i have store value and two sets of data:

$selectedColor

const productColor = {
   options: [
      {id:0, title: 'white'},
      {id:1, title: 'black'},
      {id:2, title: 'red'},
      {id:3, title: 'yellow'}
   ],
}


const productType = {
   options: [
      {id:0, title: 'somethings', hiddenInColor: 'white'},
      {id:1, title: 'somethings', hiddenInColor: 'black'},
      {
         id:2, 
         title: 'somethings', 
         hiddenInColor: 
        //here should be black AND white
        //problem is I can't understand how to use nested json with disable attribute (see below) 
      }
   ],
}

then i have populate inputs (type: radio) for product type and color

{#each productType.options as option (option.id)}
            {#if activeTab !== option.hiddenIn}
                <li>
                    <label>
                        <input type="radio" name="name" 
                            value={option.id} 
                            on:change={() => optionHasChanged(option.name, somethings)}
                            disabled={option.hiddenInColor == $selectedColor}
                            bind:group={defaultProductType}>
                        {option.title}
                    </label>
                </li>
            {/if}
        {/each}

I was trying to -> disable input IF $selectedColor == hiddenInColor

i did it like this ->

disabled={option.hiddenInColor == $selectedColor}

and it works well. But... only when you testing it against 1 value

i cant understand how to check more then 1 color at once. So basically, using my const productType -> i would like to disable id:3 if $selectedColor == 'black' || 'white'

any advices? Or maybe there is more compact solution to this? Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The simplest way to achieve this would be using an array hiddenInColors instead of a single scalar value:

const productType = {
   options: [
      {id:0, title: 'somethings', hiddenInColors: ['white']},
      {id:1, title: 'somethings', hiddenInColors: ['black']},
      {id:2, title: 'somethings', hiddenInColors: ['black','white']},
   ],
}

and then set the disabled option like this:

disabled={option.hiddenInColors.includes($selectedColor)}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!