No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Unable to set q-chip color

    Help
    2
    6
    688
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      venkyvb last edited by venkyvb

      I am trying to dynamically set the color for a q-chip in a list.

      ...
              <q-item v-for="(p, idx) in entries" :key="idx" @click.native="selectedEntry(p)">
                  <q-item-side left>
                    <q-item-tile>
                      <q-chip dense :color="getEntryColor(idx)" :text-color="getEntryColor(idx)">|</q-chip>
                    </q-item-tile>  
                  </q-item-side>
                  <q-item-main :label= "p.name"/>
                  <q-item-side tag="label"> 
                    {{ p.value | formatValue }}
                  </q-item-side>
                  <q-item-side right icon="keyboard arrow right"/>
                  <q-item-separator inset/>
              </q-item>
      ...
      

      and the getEntryColor is a simple method that returns a hex code (e.g. #ffffff) for a color

      ...
        methods: {
          getEntryColor(index) {
            if (index === 0) {
              // Summary
              return '#ffffff';
            }
            let result = this.backgroundColors[index - 1];
            return result;
          },
      ...
      

      However this doesnt seem to work. Any ideas as to what could be going wrong here?

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by

        First off, what is there to trigger your method? I think what you are looking for is a computed property.

        If that doesn’t help, can you give us a snippet of your data? Even better, create a fiddle with your code to demonstrate your issue.

        https://jsfiddle.net/rstoenescu/waugrryy/

        Scott

        V 1 Reply Last reply Reply Quote 0
        • V
          venkyvb @s.molinari last edited by

          @s-molinari I’ll prepare a jsfiddle for this example.

          Just to elaborate further, the trigger is on the “created” lifecycle hook

            created() {
              this.getUserEntries();
            },
          

          This in turn prepares the data for display of a Pie chart where the colors are populated into a backgroundColors array (as shown in the first code snippet).

          Since the entry needs to be looked up for every <q-item> I need to pass the Index to look-up the backgroundColor (hence I have this look-up set-up as a method). Is this possible with a “computed” property? (p.s. I am not using Vuex yet.).

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by s.molinari

            What you’ve explained is still not firing the method. Try it with a computed property.

            Scott

            1 Reply Last reply Reply Quote 0
            • V
              venkyvb last edited by venkyvb

              Was able to figure out the issue. <q-chip color=’#ffffff’> doesn’t seem to work (i.e. hex code). However if you give a color name ‘blue’ it works.

              1 Reply Last reply Reply Quote 0
              • s.molinari
                s.molinari last edited by

                Hmm… yeah. Looks like it only takes the Quasar color pallette. https://quasar-framework.org/components/color-palette.html

                Scott

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post