Adding a class dynamically to an element

  • martinf4630-1343608670461886474

    MartinF

    19 days ago

    I'm trying to use the phospher icon library to add icons to nav elements. Its working well until i try to add the class dynamically based on the value in the component attribute. Adding an attribute called class and then adding it with a formula works (correct icon rendered) but stops any of the styling from being applied.

    What the best way to handle this?
    1343608671103483924-CleanShot_2025-02-24_at_15.40.452x.png
  • filip_dajkovic-1343618169700352143

    Filip Dajkovic

    19 days ago

    Adding classes shouldn't be done as an Attribute, there's dedicated Classes field right below it and you can add multiple classes with dynamic logic
  • martinf4630-1343621089397440583

    MartinF

    19 days ago

    You can only add boolean values to toggle classes on and off. There are 1200 possible classes to toggle so not sure how that could work?
  • martinf4630-1343621601286950976

    MartinF

    19 days ago

    Need a way to dynamically set a class. Not sure what the Toddle way is on this one
  • 1343621609423896629-CleanShot_2025-02-24_at_16.31.362x.png
  • lucasg-1343622947037904927

    Lucas G

    19 days ago

    What styles are you referring to here
  • Ones you applied or ones from the library?
  • martinf4630-1343623136758988800

    MartinF

    19 days ago

    Just the color: and font-size: added in the styles tab.
  • they get ignored and library defaults are rendererd
  • lucasg-1343623421074083881

    Lucas G

    19 days ago

    Sounds like normal behavior if the class is applying its own styles
  • martinf4630-1343623597700157471

    MartinF

    19 days ago

    this only happens when adding the class as an attribute. the styles work fine if i add the class by giving class values (not dynamically as an attribute)
  • martinf4630-1343624557784731758

    MartinF

    19 days ago

    works fine this way
    1343624557512228896-CleanShot_2025-02-24_at_16.43.392x.png
  • martinf4630-1343624888178573324

    MartinF

    19 days ago

    Might need a bit of custom code? Want to do things 'the Toodle way' before i start hacking about
  • Tod-1343624889621413900

    Tod

    19 days ago

    Great energy @MartinF! Your continuous contribution to the toddle Community just made you advance to Community Level 6!
  • potensio-1347542916960354356

    Hanif

    8 days ago

    Hey @MartinF, mind sharing how you achieved this? I've managed to set up the header and added the appropriate classes to an <i> tag, but it doesn't seem to be rendering in my case.
    1347542916276555886-Screen_Shot_2025-03-07_at_18.26.06.png
    1347542916666495091-Screen_Shot_2025-03-07_at_18.26.21.png

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code — but accessible to your entire team!

Try toddle — it's free!

© Copyright 2024 toddle. All rights reserved.