PricingBlog

Accessing element attribute values from within a show formula

  • clinton_02060-1210224909410635806

    Clinton

    2 years ago

    I am trying to set an elements visibility based on a value set in one of it's attributes.
  • Tod-1210224911428231198

    Tod

    2 years ago

    Great energy @Clinton! Your continuous contribution to the toddle Community just made you advance to Community Level 1!
  • lucasg-1210227820731703307

    Lucas G

    2 years ago

    Use a show/hide condition and base it off the attribute. Just make sure the attribute, or your use of it, outputs Bool True/False
  • nocode.lad-1210227840184746004

    noCode.Lad

    2 years ago

    Use class or the show/hide condition
    👍1
  • Ah... @Lucas G is a speedster
    😅1
  • clinton_02060-1210231496275927110

    Clinton

    2 years ago

    How do I see the attribute from within the formula editor?
  • clinton_02060-1210232341717327922

    Clinton

    2 years ago

    The elements attributes look as follows. I want to add a formula to the Show attribute that states if "icon-name" is equal to a value from an input, in this case "icon-close", then show the element, otherwise hide it.
    1210232341536968725-image.png
  • nocode.lad-1210233800748175440

    noCode.Lad

    2 years ago

    First off, either bing the input to a variable, or add an event that updates a variable when the input changes.
  • Then using that variable, build your function. Lemme show an example
  • lucasg-1210234797591625728

    Lucas G

    2 years ago

    Don't change the 'tag' to custom things unless it is really, really needed. These tags are HTML tags and ideally you use existing tags for elements. They're for the browser to know what is what, as well as for accessibility compliance, etc
    👍1
  • clinton_02060-1210235062470053999

    Clinton

    2 years ago

    Good to know
  • lucasg-1210235256792158248

    Lucas G

    2 years ago

    Not saying never do it. It is okay to use custom HTML elements sometimes but as a rule of thumb, you'll want to just try to use existing elements
  • Back to the original question though
  • What input are you referring to?
  • Where is this input coming from?
  • clinton_02060-1210235445041172530

    Clinton

    2 years ago

    It's was more for readability in the elements tree - I was getting lost
  • lucasg-1210235486459658310

    Lucas G

    2 years ago

    Yeah, I understand no worries lol
    😅1
  • There are 2 types of attributes in toddle. One is regular HTML attributes that you can set in the tab taht you screenshotted
  • And there are component attributes that you can set up (you can see them on the right sidebar when there is nothing selected in the element tree)
  • clinton_02060-1210235925414551573

    Clinton

    2 years ago

    Okay - so the goal is to create a component that holds all the icons I am using throughout the application - the component takes in an "icon-name" attribute which is the input I am talking about.
  • 1210236073758691389-image.png
  • nocode.lad-1210236178146525204

    noCode.Lad

    2 years ago

    Oh... That changes thing
  • clinton_02060-1210236267418361949

    Clinton

    2 years ago

    I had the idea to then show/hide the elements based on the icon-name input
  • lucasg-1210236343775531088

    Lucas G

    2 years ago

    I recommend making icons into components and reusing them that way
  • clinton_02060-1210236373865336852

    Clinton

    2 years ago

    Sorry, I should have added more context from the start
  • nocode.lad-1210236430530650202

    noCode.Lad

    2 years ago

    Have you aded the attribute to the parent component
  • clinton_02060-1210236454945689600

    Clinton

    2 years ago

    Each individual icon?
  • lucasg-1210236474902061108

    Lucas G

    2 years ago

    Yes
  • clinton_02060-1210236524327731272

    Clinton

    2 years ago

    Yes
  • 1210236586034204762-image.png
  • lucasg-1210236680779333652

    Lucas G

    2 years ago

    1210236680573947964-image.png
  • 1207737439440085063-@Clinton
    nocode.lad-1210236780205572167

    noCode.Lad

    2 years ago

    Ok perfect. It should be available in the formula editor
  • 128651941143117824-@Lucas G
    nocode.lad-1210237032627048549

    noCode.Lad

    2 years ago

    I think the way he is doing it is cleaner. Less components and every icon in a single place
  • Tod-1210237034338193438

    Tod

    2 years ago

    Great energy @noCode.Lad! Your continuous contribution to the toddle Community just made you advance to Community Level 6!
  • clinton_02060-1210237197064601680

    Clinton

    2 years ago

    Yeah this is the intention
  • Tod-1210237199191384064

    Tod

    2 years ago

    Great energy @Clinton! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • lucasg-1210237233483743242

    Lucas G

    2 years ago

    Yeah, I understand that point. I won't say don't do it lol
  • To directly answer it though, what you'd do is set a show/hide formula for each SVG
  • 1210237595854966874-image.png
    1
  • It would look like that
  • You'll need to set it for each SVG
  • clinton_02060-1210238050551201843

    Clinton

    2 years ago

    I see, so I cant read the value of the attribute on the element i.e. this.iconName.value
  • lucasg-1210238198572261386

    Lucas G

    2 years ago

    Those are HTML attributes
  • You'd need to create a custom formula if you want to use those
  • clinton_02060-1210238548070899712

    Clinton

    2 years ago

    It would be great to have custom formulas within components
  • lucasg-1210238774135627806

    Lucas G

    2 years ago

    What do you mean by that
  • You can create custom formulas and they are available project wide
  • They're nice if you are comfortable with JS
  • The way I showed up there though would be without the use of any custom code so yeah
  • clinton_02060-1210239291347963904

    Clinton

    2 years ago

    To add them here, within the component itself. I can only see a way of adding them within the main app
    1210239291163152405-image.png
  • lucasg-1210239375061950524

    Lucas G

    2 years ago

    A bit of a spoiler, I'm working on a pack that I'll share once packages are released
  • It'll include some icons with settings and stuff
  • I hope they'll be useful but now I'm wondering if it would be useful to implement it the way you're showing 🤔
  • Right now, they would appear when you search the catalog (the modal when you press E)
  • The only issue I'm seeing is that people would need to know the name for each icon to use it
  • Hmm maybe not then lol
  • lucasg-1210239886821425234

    Lucas G

    2 years ago

    Yes, custom formulas are project wide
  • Which I prefer, so they don't have to be remade
  • lucasg-1210240340779470899

    Lucas G

    2 years ago

    Something I recommend you add is settings for each icon as well, very handy
  • 1210240345036820480-image.png
    👍1
    💡1
  • 1210240390897082368-image.png
  • You can use them to dynamically set size and color settings for each icon
  • For example
  • I think that would be pretty cool for your icon component
  • nocode.lad-1210242340376023120

    noCode.Lad

    2 years ago

    I'm pants at JS 😅, custom formula is a no go for me unfortunately. Even copying and pasting requires some tweaking which I can't do for the life of me. And its strange cos I had HTML & CSS down easily
  • lucasg-1210242699764957314

    Lucas G

    2 years ago

    What do you mean by copy/paste requires tweaking?
  • nocode.lad-1210242791167361116

    noCode.Lad

    2 years ago

    The only thing I'm usually able to edit is scripts I paste directly in the canvas. As I simply need to change the target element inside "get element by" or something like that
  • nocode.lad-1210243086870126592

    noCode.Lad

    2 years ago

    Yeah, generally you need to change one or two things to suit your particular use case in a lot of copied code. Not always will the code work 100% out of the box without you having to tweak something
  • lucasg-1210243341166575686

    Lucas G

    2 years ago

    Oooh like stuff you get from some other source
  • Gotcha
  • lucasg-1210243673044820018

    Lucas G

    2 years ago

    I have a couple custom actions/formulas but they're hardly needed tbh, toddle's formula editor is very powerful out of the box
  • nocode.lad-1210244099521777714

    noCode.Lad

    2 years ago

    Agreed. And there's still more formula to come. They'd probably add a formula that can target html attributes in the near future too
  • lucasg-1210244406398025819

    Lucas G

    2 years ago

    Hmm maybe. They don't add new formulas often, or at least they haven't in the time I've been using toddle
  • clinton_02060-1210247331430146168

    Clinton

    2 years ago

    A formula for HTML attributes would be great
  • lucasg-1210247845056086076

    Lucas G

    2 years ago

    Hmm I had not came across that use case myself but I could maybe make a formula for it and share it
  • clinton_02060-1210247922029953095

    Clinton

    2 years ago

    It would need an icon browser
  • lucasg-1210248167124373545

    Lucas G

    2 years ago

    They will work as current elements do. They will be available to choose from via the catalog that appears when you go to add a new element
    👍1
  • clinton_02060-1210248396154212372

    Clinton

    2 years ago

    I wrote a custom formula to handle a drag & drop list which after a fair amount wrangling I got it to work.
    👌🏾1
  • lucasg-1210248520695816362

    Lucas G

    2 years ago

    Ah I will include one of those in my pack as well lol