Skip to content

Commit

Permalink
added improved submitting state and styles to forms
Browse files Browse the repository at this point in the history
  • Loading branch information
hotdoy committed Dec 10, 2019
1 parent 1c2a180 commit 81278cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
25 changes: 17 additions & 8 deletions css/forms.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
form{
transition: all 0.2s;
}

.form-field{
margin-top: 1rem;
}
Expand Down Expand Up @@ -218,15 +222,20 @@ LOADER
###########################################################
*/

.form-loader{
display: none;
form.submitting{
opacity: 0.7;
}

form.submitting button:after{
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: var(--bg-color);
background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve"><path fill="currentColor" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"/></path></svg>');
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: inherit;
border-radius: 4px;
background-image: url('../images/spinner-white.svg');
background-repeat: no-repeat;
background-position: center;
}
1 change: 1 addition & 0 deletions images/spinner-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
form.submit(function(e) {
e.preventDefault();

var loader = $('<div class="form-loader"></div>');
form.append(loader);
form.addClass('submitting');
form.find('button').blur();
loader.fadeTo(500, 0.7);

$.ajax({
url: form.attr('action'),
Expand All @@ -23,12 +21,12 @@
$(form)[0].reset();
console.log('form submission success!');
notify(message, status);
loader.fadeOut(500);
form.removeClass('submitting');
},
error: function() {
console.log('form submission failed!!!');
notify('Submission failed. Refresh page and retry.', '#f44336');
loader.fadeOut(500);
form.removeClass('submitting');
}
});
});
Expand Down

0 comments on commit 81278cc

Please sign in to comment.