diff --git a/src/Foundation.hs b/src/Foundation.hs index 22af31b8f..70155f9a4 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1071,6 +1071,7 @@ siteLayout' headingOverride widget = do -- addScript $ StaticR js_utils_alerts_js -- addScript $ StaticR js_utils_asidenav_js -- JavaScript utils + addScript $ StaticR js_utils_asyncForm_js addScript $ StaticR js_utils_asyncTable_js addScript $ StaticR js_utils_checkAll_js addScript $ StaticR js_utils_form_js diff --git a/src/Handler/Admin.hs b/src/Handler/Admin.hs index 19b84adf3..653f91979 100644 --- a/src/Handler/Admin.hs +++ b/src/Handler/Admin.hs @@ -121,7 +121,7 @@ postAdminTestR = do let emailWidget' = wrapForm emailWidget def { formAction = Just . SomeRoute $ AdminTestR , formEncoding = emailEnctype - , formAttrs = [("data-ajax-submit", "")] + , formAttrs = [("uw-async-form", "")] } diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index 7b60a6da3..81dc1ac66 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -261,7 +261,7 @@ postHelpR = do let form = wrapForm formWidget def { formAction = Just $ SomeRoute HelpR , formEncoding = formEnctype - , formAttrs = [ ("data-ajax-submit", "") | isModal ] + , formAttrs = [ ("uw-async-form", "") | isModal ] } formResultModal res HelpR $ \HelpForm{..} -> do diff --git a/static/css/utils/asyncForm.scss b/static/css/utils/asyncForm.scss index a0f9956dd..bd5a97a41 100644 --- a/static/css/utils/asyncForm.scss +++ b/static/css/utils/asyncForm.scss @@ -1,4 +1,4 @@ -.async-form-response { +.async-form__response { margin: 20px 0; position: relative; width: 100%; @@ -7,15 +7,15 @@ padding-top: 60px; } -.async-form-response::before, -.async-form-response::after { +.async-form__response::before, +.async-form__response::after { position: absolute; top: 0px; left: 50%; display: block; } -.async-form-response--success::before { +.async-form__response--success::before { content: ''; width: 17px; height: 28px; @@ -24,7 +24,7 @@ transform: translateX(-50%) rotate(45deg); } -.async-form-response--info::before { +.async-form__response--info::before { content: ''; width: 5px; height: 30px; @@ -32,7 +32,7 @@ background-color: #777; transform: translateX(-50%); } -.async-form-response--info::after { +.async-form__response--info::after { content: ''; width: 5px; height: 5px; @@ -40,14 +40,14 @@ transform: translateX(-50%); } -.async-form-response--warning::before { +.async-form__response--warning::before { content: ''; width: 5px; height: 30px; background-color: rgb(255, 187, 0); transform: translateX(-50%); } -.async-form-response--warning::after { +.async-form__response--warning::after { content: ''; width: 5px; height: 5px; @@ -56,14 +56,14 @@ transform: translateX(-50%); } -.async-form-response--error::before { +.async-form__response--error::before { content: ''; width: 5px; height: 40px; background-color: #940d0d; transform: translateX(-50%) rotate(-45deg); } -.async-form-response--error::after { +.async-form__response--error::after { content: ''; width: 5px; height: 40px; @@ -71,7 +71,7 @@ transform: translateX(-50%) rotate(45deg); } -.async-form-loading { +.async-form--loading { opacity: 0.1; transition: opacity 800ms ease-out; pointer-events: none; diff --git a/static/js/utils/asyncForm.js b/static/js/utils/asyncForm.js index aa57ed2a0..c7fde55c5 100644 --- a/static/js/utils/asyncForm.js +++ b/static/js/utils/asyncForm.js @@ -1,33 +1,62 @@ (function collonadeClosure() { 'use strict'; - window.utils = window.utils || {}; + /** + * + * Async Form Utility + * prevents form submissions from reloading the page but instead firing an AJAX request + * + * Attribute: uw-async-form + * (works only on