Collapse Show - is it a toggle?

Hi!
I've got some code with a collapse in it:

Whenever the code "546847RecoveryTooSoon" is given by the server the Collapse is set to show.

But, I noticed that if I trigger it again it collapses.
So, I'm wondering if the "show" attribute is actually more like a toggle?

If it is, how to I get it to remain showing as long as that code keeps getting triggered?

THE CODE:

<div class="collapse" id="id_collapse_RecoveryTooSoon" is="dmx-bs5-collapse" dmx-bind:show="(form_recoverPassword2.lastError.response == '546847RecoveryTooSoon')">
  <p class="bg-warning">
    <i class="fas fa-clock"></i>
    Oops! You tried again too quickly. Wait at least five seconds.
  </p>
 </div>

Not sure what you're after my friend...
From what I understood, you have a serverconnect form and whenever it is submitted , you check something (counting a response time?) in your api and if a condition is true then you through an error response with value '546847RecoveryTooSoon'.
Then when the form is submitted in your page you try to get that by reading the .lastError.response if it is == '546847RecoveryTooSoon'. Then you show your collapse.
Otherwise it is collapsed.

Am I right?
When the form is submitted, do you reset the form?

If you just handle the collapse (show/hide) via the form event?

  1. remove the dmx-bind:show from the collapse
  2. and check if the form.lastError.response == '546847RecoveryTooSoon' then show
    Could that work?

Everything is working fine, I just don't know why the collapse opens and closes both on a "show" command.

But yes, I'm counting response time.
Whenever someone submits an attempt to recover a password the database records the time.

If someone submits another attempt within five seconds it makes them wait.

If it's within 5 seconds of their previous attempt, the server will throw a 200 response with the response "546847RecoveryTooSoon" - that number is irrelevant, just something I made up so I don't accidentally get that value from somewhere else.

But whenever the form's last.Error.response is "546847RecoveryTooSoon" then it shows the collapse which has the message telling them to wait.

I'm not sure why it collapses if I receive that response again.

you don't reset the form?

Can you add an event on your form and show the .lastError.response value (notification) every time it is submitted?
Can you please share the code?

Here's the full code.
I didn't add the .lastError.response value (notification) every time yet, as I was using my browser's console to see those values. I have them output right now.

<!doctype html>
<html>

<head>
    <base href="/">
    <script src="dmxAppConnect/dmxAppConnect.js"></script>
    <meta charset="UTF-8">
    <title>Recover Account Step 2</title>

    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="bootstrap/5/css/bootstrap.min.css" />
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js" integrity="sha256-CutOzxCRucUsn6C6TcEYsauvvYilEniTXldPa6/wu0k=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="css/style.css" />
    <link rel="stylesheet" href="dmxAppConnect/dmxNotifications/dmxNotifications.css" />
    <script src="dmxAppConnect/dmxNotifications/dmxNotifications.js" defer></script>
    <link rel="stylesheet" href="dmxAppConnect/dmxValidator/dmxValidator.css" />
    <script src="dmxAppConnect/dmxValidator/dmxValidator.js" defer></script>
    <script src="dmxAppConnect/dmxBrowser/dmxBrowser.js" defer></script>
    <script src="dmxAppConnect/dmxBootstrap5Collapse/dmxBootstrap5Collapse.js" defer></script>
    <script src="dmxAppConnect/dmxFormatter/dmxFormatter.js" defer></script>
</head>

<body is="dmx-app" id="ForgotPassword">
    <div is="dmx-browser" id="browser1"></div>
    <dmx-value id="var_hideOrShowMessage" dmx-bind:value="0"></dmx-value>
    <dmx-value id="var_show_tooSlowMessage" dmx-bind:value="form_recoverPassword2.lastError.response"></dmx-value>
    <dmx-notifications id="notifies1">

    </dmx-notifications>
    <header class="text-center">
        <div class="container text-center">
            <img src="assets/images/RevolutionLinkLogo1%20copy-smaller.png" class="img-fluid align-self-center">
        </div>
    </header>
    <div class="contentArea">
        <main class="text-center">

            <div class="row justify-content-center" id="id_row_heading">
                <div class="col">
                    <div class="row">
                        <div class="col">

                            <h3 class="text-primary" id="id__heading">Password Recovery Step 2</h3>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row text-center row-cols-7">

                <div class="col text-center">
                    <div class="row align-items-center justify-content-center">
                        <form is="dmx-serverconnect-form" id="form_recoverPassword2" method="post" action="dmxConnect/api/security/PasswordReset_reset_it.php" dmx-generator="bootstrap4" dmx-form-type="horizontal" dmx-on:success="notifies1.success('Success!')">
                            <div class="form-group row">
                                <div class="col-sm-10">
                                    <input type="text" class="form-control form-control-lg" id="inp_email" name="email" aria-describedby="inp_email_help" placeholder="Enter Email" required="" data-rule-email="">
                                    <small id="inp_email_help" class="form-text text-muted">This must match the email you got your recovery form from.</small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-10">
                                    <input type="text" class="form-control form-control-lg" id="inp_verificationcode" name="verificationcode" aria-describedby="inp_verificationcode_help" placeholder="Enter Verificationcode" required="" data-rule-alphanumeric="" maxlength="12">
                                    <small id="inp_verificationcode_help" class="form-text text-muted">This code must match EXACTLY as the email sent it.</small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-10">
                                    <input type="password" class="form-control form-control-lg" id="inp_password" name="password" aria-describedby="inp_password_help" placeholder="Enter Password" data-rule-equalto="passwordConfirm" required="" data-rule-nowhitespace="" maxlength="20" minlength="5">
                                    <small id="inp_password_help" class="form-text text-muted">Enter a new, secure, password.<br>At least 5 characters.<br></small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-10">
                                    <input type="password" class="form-control form-control-lg" id="inp_passwordConfirm" name="passwordConfirm" aria-describedby="inp_passwordConfirm_help" placeholder="Enter Confirm Password" data-rule-equalto="password" required="">
                                    <small id="inp_passwordConfirm_help" class="form-text text-muted">Make sure the passwords match.</small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-2">&nbsp;</div>
                                <div class="col-sm-10">
                                    <button type="submit" class="btn btn-primary" dmx-bind:disabled="state.executing" dmx-on:click="form_recoverPassword2.submit();form_recoverPassword2.reset()">Save <span class="spinner-border spinner-border-sm" role="status" dmx-show="state.executing"></span></button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>


            </div>
            <div class="row align-items-center text-center">
                <div class="collapse" id="id_collapse_RecoveryTooSoon" is="dmx-bs5-collapse" dmx-bind:show="(form_recoverPassword2.lastError.response == '546847RecoveryTooSoon')">
                    <p class="bg-warning"><i class="fas fa-clock"></i>&nbsp;Oops! You tried again too quickly. Wait at least five seconds.</p>
                </div>
                <div class="collapse" id="id_collapse_tooslow" is="dmx-bs5-collapse" dmx-bind:show="form_recoverPassword2.lastError.response=='546845TooLongCode'">

                    <p class="text-danger"><i class="fas fa-hourglass-end"></i>&nbsp;Sorry, but you took too long to respond.<br>You can <a href="ForgotPassword.php">try again</a> if you like.<br>Don't be so slow next time.&nbsp;&nbsp;<i class="fas fa-grin-beam-sweat"></i></p>
                </div>
                <div class="collapse" id="id_collapse_codeWrong" is="dmx-bs5-collapse" dmx-bind:show="form_recoverPassword2.lastError.response=='546846CodeWrong'">

                    <i class="fas fa-skull-crossbones fa-2x"></i>
                    <p class="text-danger">Nope, that code or email ain't right.</p>
                </div>
                <div class="collapse" id="id_collapse_DoNotUseThatPass" is="dmx-bs5-collapse" dmx-bind:show="form_recoverPassword2.lastError.response=='546846PassNoGood'">

                    <i class="fas fa-exclamation-triangle fa-3x"></i>
                    <p class="text-danger">You cannot use that password.</p>
                </div>
                <div class="collapse text-success" id="id_collapse_passwordUpdated" is="dmx-bs5-collapse" dmx-bind:show="form_recoverPassword2.lastError.response=='546848PasswordUpdated'">

                    <i class="fas fa-thumbs-up fa-4x"></i>
                    <p class="text-success">Password successfully updated.<br>Please <a href="index.php">login again</a>, now.</p>
                </div>
            </div>
        </main>
    </div>
    <script src="bootstrap/5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

I think this is causing the problem...
you submit the form and immediately reset it...

Please try this:
on button click, only submit the form (NO RESET).
dmx-on:click="form_recoverPassword2.submit()"
This way you leave the form's response from the last submittion available to control if the collapse should show or hide

Then you can define what to do if the form is submitted with success (not fast etc) on your form success event. Then you can reset the form.

Oops. In response to that suggestion, looks like part of my message didn't get included. Aaaaaand it was actually here waiting for me when I clicked "reply":

I haven't added a form reset yet, while I was testing to make it easier for me.

That reset was what I added after your first response.
The collapse closes on the second "show" even without that.

This is true, confirmed using a 500 server connect status.

<dmx-serverconnect id="serverconnect1" url="/api/wapplercommunity/collapse_test" noload="true"></dmx-serverconnect>
<button id="btn1" class="btn" dmx-on:click="serverconnect1.load({})">Button</button>
<div class="collapse" id="collapse1" is="dmx-bs5-collapse" dmx-bind:show="serverconnect1.lastError.status==500">
    <p>Collapse body text goes here.</p>
</div>

Honestly, don't know..
Maybe it's an expected behavior..
AC1 does the same thing..

1 Like

Thank you for confirming.

That's really my question, is it expected behavior?

I thought it would be called a toggle if that was the case.

But, this is called a show so I figured it would only show, even if triggered multiple times.

Hi Jeff,

Collapse functions as a toggle when clicked on the collapse element. When you click on the collapse element, show is added / removed to show or hide the collapsible element.

If the idea is to show and / or disable the submit button for 5 seconds, then an option would be to use a front-end countdown timer. You can dynamically show and disable the submit button until the countdown timer is greater than 0.

Another change I would suggest is to set the binding for show to dmx-class:show="(form_recoverPassword2.lastError.response == '546847RecoveryTooSoon')". It's a dynamic class toggle property instead of a dynamic binding.

1 Like

Good to know the "show" function on a collapse is actually a toggle.