Can I have multiple events in a components?

  • A-Chivas

    24 days ago

    Can I have multiple events in a components? also why do I have to type events in components? its really confusing, I need to assign multiple events and I am confused, plz help
  • Tom Ireland

    24 days ago

    Yes, you can have multiple events in a component. What is it you're trying to do with the events in a component? When you say "why do I have to type events", do you mean when creating an event in a component and giving it a name? If so, this is because you need to trigger an event from a component in order to send data out of it to the page or a parent component, so the event you create is up to you in terms of what it's called or what it sends back.

    Common examples are click events e.g. for a button component. You create an event called something like "onClick" or "buttonClick" and trigger it from within the component e.g. on click of a button, trigger the "buttonClick" event. This means when you add a button to the page, you can use the event to do further actions.

    I can demo an example if you like?
  • A-Chivas

    24 days ago

    I'll share a demo quick
    πŸ‘1
  • A-Chivas

    24 days ago

    @Tom Ireland
  • Tom Ireland

    24 days ago

    Here's a more complicated example:

    https://www.tella.tv/video/components-and-events-part-2-hpmk

    And here's a link to Andreas' video regarding abstraction:

    https://youtu.be/PQjMZ_0ju1g?si=f-5rYCjxItt6DthT
  • Tom Ireland

    24 days ago

    This is a good read and watch as well: https://toddle.dev/docs/events
  • /attachments/1319670501253185576/1319697592132567121/image.png

    A-Chivas

    24 days ago

    what ti need to trigger this on click?
    image.png
  • A-Chivas

    24 days ago

    I am guessing this I will have to handle on page level
  • A-Chivas

    24 days ago

    @Tom Ireland
  • Tod

    24 days ago

    Great energy @A-Chivas! Your continuous contribution to the toddle Community just made you advance to Community Level 6!
  • Tom Ireland

    24 days ago

    Yes, it's likely you will need to trigger the click event from the component and then update the data/state at the page level. Like I mentioned in my first video, it really depends on the scope of your application and what you need it to do as to how to handle things within the context of a component or at page level. Looking at the variable naming, it looks like you might be creating a number of different variables for each item you're inputting, etc. I'd highly recommend looking at data structures (objects and arrays) to help manage this. It means fewer variables and less complex logic in the long run.

    See https://youtu.be/8gOxQhhVohA?si=oKGM1E_8SK-gocc3
  • A-Chivas

    24 days ago

    I just need the same 4 variables the event is also the same, is there a way to keep them as is and just change the variables the events will be the same, I can prolly just link them in
  • A-Chivas

    24 days ago

    I will look into this
  • Tom Ireland

    24 days ago

    If you're going to use the variables in the component, you'll need to recreate them or copy/paste them in the component. Then you'll need an event to send the data back to the page if you're planning on updating an API or something like that. Hard to say without access to your project and broader understanding of what you're trying to achieve.
  • A-Chivas

    24 days ago

    wll you be avalable for a quick call?
  • Tom Ireland

    24 days ago

    Sadly I'm not available for a call this evening. If you can provide an explainer via video, this will give me the chance to have a look when I get a bit more time. If you do that, please be as descriptive as possible in terms of the problem you're trying to solve and I'll try to return a video with some suggestions. Failing that, there may be others in the community here willing to help you out. πŸ‘
  • Lucas G

    24 days ago

    I haven't read through all of this but I think I get the gist of it
  • You have a component with an input and a search dropdown and a button right?
  • The component itself should handle all of that logic and just pass up the selected item in the event
  • That way if you repeat the component, each one will handle its own state/variables
  • Based on the look of your element tree, you could use some refactoring and create a few components
  • A-Chivas

    24 days ago

    no problem mate, thanks for the help
    πŸ‘1

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.