Forums

Forums / General Discussions / tpc:pre-submit with async function

tpc:pre-submit with async function

12 posts, 2 answered
  1. Missing user
    Missing user avatar
    25 May 2022
    Link to this post
    Hi,
    I am trying to call an api with jquery in an async function. Because the pre-submit is not an async function, it is not waiting for the call to finish. it is completing the submit event first and doesn't get the required values. Is there anyway to make any submit events async? 

    Thanks
  2. Missing user
    Missing user avatar
    30 May 2022 in reply to Missing user
    Link to this post
    Hello Uygar,

    I don't believe you can "make the submit event async".

    One thing you can do is have a global flag (set to true/false). On the first submit of the form (while the flag is still flase), return false in pre-submit, preventing the submission. Once your async function completes, set the flag to true and submit the form again. You can even have a loading symbol or whatever works best with your UI appear after the first click.

    Let me know if you have any questions,

    Brady
    TPC Web Developer
  3. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    Hi Brady, 

    Thank you, I am now trying that solution. I tried to re-submit the form with javascript but it is failing. Can you write how can I re-submit the page with javascript?

    Thanks,
    Uygar
  4. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    Hello Uygar,

    What do you mean it is failing?!

    If you are using the TPC Submit Button: tpc.forms[0].submitbutton._input.click();
    If you are using the Sitefinity Submit Button (and it's the only one on the page): $(".sf-SubmitButton").click();

    All the best,

    Brady
    TPC Web Developer
    Last modified on 31 May 2022 21:05 by Missing user
  5. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    Hi Brady,
    I am using tpc submit. I am getting this error:

    VM8046:1 Uncaught TypeError: Cannot read properties of undefined (reading '_input')
        at <anonymous>:1:27
  6. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    tpc.forms[0].submitbutton is undefined. 
  7. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    Hey Uygar,

    No worries, the field name may be different on your submit button.

    If you edit the form and click Edit on the submit button you should see a More Options dropdown. Expand this and you should see field name. Copy paste this value and replace submitbutton in the sample I provided to you.

    Let me know if that works,

    Brady
    TPC Web Developer
  8. Missing user
    Missing user avatar
    31 May 2022 in reply to Missing user
    Link to this post
    Hi Brady, I only have Template and CSS classes under the more options. I couldn't find name in other screens either.

    When I check the elements from debugging, this is what I have:

    <button type="submit" class="btn btn-primary mt-3 pull-right" data-tpc-role="submit-button" data-tpc-button-type="submit">Save &amp; Continue</button>
  9. Missing user
    Missing user avatar
    Answered
    31 May 2022 in reply to Missing user
    Link to this post
    Hello Uygar,

    So more than likely that's the Sitefinity submit button (title is likely just Submit Button vs TPC Submit Button).

    But because the correct button is still rendering, I will assume you're using this form in a form flow?

    Regardless, the following snippet should work for you: $("[data-tpc-role='submit-button']").click();

    All the best,

    Brady
    TPC Web Developer
  10. Missing user
    Missing user avatar
    Answered
    31 May 2022 in reply to Missing user
    Link to this post
    Hi Brady, thank you so much, this one worked :) 
  11. Missing user
    Missing user avatar
    12 Sep 2023
    Link to this post
    Thank you, I am now trying that solution. 
    https://hdstreamz.uno
    https://krnl.fun/

    Last modified on 16 Nov 2023 09:11 by Missing user
  12. Missing user
    Missing user avatar
    02 Apr 2024
    Link to this post
    Thank you,
12 posts, 2 answered