PricingBlog

[Resolved] Update Variable with form submit

  • successfulgeek-1192203979527041164

    SuccessfulGeek

    2 years ago

    I can't get a variable to update with a submit event, but I can do it with the input event. I want it to update with submit though. Here is the video I made around it and I am probably missing something very simple. https://vimeo.com/899614660/ee973c9ff6?share=copy
    1
  • lucasg-1192204900042547260

    Lucas G

    2 years ago

    The submit event is for the form element
  • 1192204914718408824-image.png
  • lucasg-1192205196969910292

    Lucas G

    2 years ago

    It is set on the form element itself and it is triggered when the form is submitted
  • You can then also use that same submit even to send the message to the API
  • successfulgeek-1192206540300632205

    SuccessfulGeek

    2 years ago

    Ah so I can't just have an input, I have to use the Form element instead?
  • Or is the input element to add to a Form?
  • lucasg-1192207230834061504

    Lucas G

    2 years ago

    The form element is a wrapper for your input and button elements
  • successfulgeek-1192207258617139360

    SuccessfulGeek

    2 years ago

    got it, thanks so much!
  • lucasg-1192207862877925406

    Lucas G

    2 years ago

    Just make sure that your submit event is on the form element itself, not on the input
  • successfulgeek-1192207958562582538

    SuccessfulGeek

    2 years ago

    got it!
    👍1
  • successfulgeek-1192208619446485105

    SuccessfulGeek

    2 years ago

    Ok I got it set but when I test it, my variable text shows undefined briefly and then the page resets...
    1192208619635212328-image.png
  • lucasg-1192209381677342852

    Lucas G

    2 years ago

    Ah, include a "Prevent Default" event
  • successfulgeek-1192209406423728261

    SuccessfulGeek

    2 years ago

    ah will do
  • Tod-1192209408990642176

    Tod

    2 years ago

    Great energy @SuccessfulGeek! Your continuous contribution to the toddle Community just made you advance to Community Level 3!
  • lucasg-1192209479752745120

    Lucas G

    2 years ago

    By default, form submits always refresh the browser page
  • Standard browser behavior
  • successfulgeek-1192209655041101934

    SuccessfulGeek

    2 years ago

    that makes sense
  • successfulgeek-1192209984327516250

    SuccessfulGeek

    2 years ago

    hmmm still not updating, i will keep playing with it and reverrse engineering the learnfromprompt project
  • lucasg-1192211548060516474

    Lucas G

    2 years ago

    I believe the prompt studio likely uses 2 variables
  • One for the input and another for the message thread it displays
  • successfulgeek-1192211658001625209

    SuccessfulGeek

    2 years ago

    yeah I am trying to figure out how to tie them together in the workflow now
  • lucasg-1192211838201512056

    Lucas G

    2 years ago

    You would have the input set to a variable and on the submit event, append that to an array of messages that is displayed as the convo
  • stockton_f-1192216391982522378

    Stockton

    2 years ago

    I think I did some things wrong here, but here's a way to think about it https://share.zight.com/o0uO40Ap
  • lucasg-1192217252192337980

    Lucas G

    2 years ago

    He'll likely want to have a dedicated variable for the messages that stores an array of user inputs and ai messages
  • successfulgeek-1192217284995977327

    SuccessfulGeek

    2 years ago

    The two variable method might be what I need for this. That way I can also submit that "display text" variable to ChatGPT and such
  • Yeah I definitely eventually want to have one for message box for the user input and another for the GPT response but I am trying to take baby steps and understand this as I go 🙂
  • stockton_f-1192217466194104372

    Stockton

    2 years ago

    Just saw the array part, here's a followup https://share.zight.com/BluqgAwl
  • successfulgeek-1192217563518734407

    SuccessfulGeek

    2 years ago

    I appreciate all the help as I learn through these things
  • stockton_f-1192217677171798076

    Stockton

    2 years ago

    lol so now we can try one more version that has the user input and the chat response...
  • lucasg-1192217821988536431

    Lucas G

    2 years ago

    Store those two in 1 variable. Make it an array of objects, one user and one ai
  • It'll be simpler for you to display the conversation
  • successfulgeek-1192217988644999270

    SuccessfulGeek

    2 years ago

    I will definitely have to use an Object to set the submitted messages role as user and then the response as gpt or something
  • lucasg-1192218023206064219

    Lucas G

    2 years ago

    Right
  • Sounds like you got it 👍
  • successfulgeek-1192218230614397039

    SuccessfulGeek

    2 years ago

    I am sure I will have more questions but I will keep banging against this and learn slowly. The setting variable as array I think will be the big thing I need
  • stockton_f-1192218300923510834

    Stockton

    2 years ago

    Lucas teaching us both 🙂
  • successfulgeek-1192218716482572389

    SuccessfulGeek

    2 years ago

    So to start something like this?
    1192218716339974316-image.png
  • and I have the input bound to the userInput variable
  • this formula is on the form on submit
  • userInput is a string and messages is an Array
  • stockton_f-1192221295962767581

    Stockton

    2 years ago

    I'm trying it as well. This is what I have so far
    1192221295765627060-tutorialz_-_arrays_Toddle_editor_2024-01-03_at_2.41.36_PM.jpg
  • ^^ This is the submit action.

    To start I just have an empty array [ ]
  • 1192221502767112284-tutorialz_-_arrays_Toddle_editor_2024-01-03_at_2.42.32_PM.jpg
  • successfulgeek-1192222135305895966

    SuccessfulGeek

    2 years ago

    I got the variable to update, now i just gotta work on display
    1192222135133937685-image.png
  • successfulgeek-1192222478156697800

    SuccessfulGeek

    2 years ago

    Woo I have a start!
    1192222477955375164-image.png
  • stockton_f-1192222558486020176

    Stockton

    2 years ago

    awwww yeah!
  • btw which tutorial are you following?
  • But I am trying to follow a Bubble video for the overall structure
  • I have no experience with Bubble so totally learning from scratch
  • stockton_f-1192224004258402344

    Stockton

    2 years ago

    Very cool! Thank you
  • successfulgeek-1192634033570598932

    SuccessfulGeek

    2 years ago

    [Resolved] Update Variable with form submit