more design on forms done, reactive validation stripes added
This commit is contained in:
parent
c70cefa800
commit
1660c867fe
@ -18,6 +18,7 @@
|
|||||||
--whitebase: #FCFFFA;
|
--whitebase: #FCFFFA;
|
||||||
--greybase: #B1B5C0;
|
--greybase: #B1B5C0;
|
||||||
--fontbase: #34303a;
|
--fontbase: #34303a;
|
||||||
|
--fontsec: #5b5861;
|
||||||
|
|
||||||
|
|
||||||
/* THEME INDEPENDENT COLORS */
|
/* THEME INDEPENDENT COLORS */
|
||||||
|
|||||||
@ -23,9 +23,9 @@ table.js-sortable th.sorted-desc::after {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table.js-sortable th.sorted-asc::after {
|
table.js-sortable th.sorted-asc::after {
|
||||||
border-bottom: 8px solid var(--lightbase);
|
border-top: 8px solid var(--lightbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.js-sortable th.sorted-desc::after {
|
table.js-sortable th.sorted-desc::after {
|
||||||
border-top: 8px solid var(--lightbase);
|
border-bottom: 8px solid var(--lightbase);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,26 +1,41 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function() {
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
if (!window.utils) {
|
if (!window.utils) {
|
||||||
window.utils = {};
|
window.utils = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// makes <label> smaller if <input> is focussed
|
// makes <label> smaller if <input> is focussed
|
||||||
window.utils.reactiveInputLabel = function(input, label) {
|
window.utils.reactiveInputLabel = function(input, label, staticLabel) {
|
||||||
|
// updates to dom
|
||||||
|
if (staticLabel === true) {
|
||||||
|
label.classList.remove('reactive-label');
|
||||||
|
}
|
||||||
if (input.value.length > 0) {
|
if (input.value.length > 0) {
|
||||||
label.classList.add('reactive-label--small');
|
if (staticLabel === false) {
|
||||||
|
label.classList.add('reactive-label--small');
|
||||||
|
}
|
||||||
if (label.parentElement.classList.contains('form-group')) {
|
if (label.parentElement.classList.contains('form-group')) {
|
||||||
label.parentElement.classList.add('form-group--valid');
|
label.parentElement.classList.add('form-group--valid');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
label.parentElement.classList.remove('form-group--valid');
|
label.parentElement.classList.remove('form-group--valid');
|
||||||
}
|
}
|
||||||
input.addEventListener('focus', function() {
|
// add event listeners
|
||||||
label.classList.add('reactive-label--small');
|
if (staticLabel === false) {
|
||||||
});
|
input.addEventListener('focus', function() {
|
||||||
label.addEventListener('click', function() {
|
label.classList.add('reactive-label--small');
|
||||||
label.classList.add('reactive-label--small');
|
});
|
||||||
input.focus();
|
label.addEventListener('click', function() {
|
||||||
});
|
label.classList.add('reactive-label--small');
|
||||||
|
input.focus();
|
||||||
|
});
|
||||||
|
input.addEventListener('blur', function() {
|
||||||
|
if (input.value.length < 1) {
|
||||||
|
label.classList.remove('reactive-label--small');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
input.addEventListener('input', function() {
|
input.addEventListener('input', function() {
|
||||||
if (label.parentElement.classList.contains('form-group')) {
|
if (label.parentElement.classList.contains('form-group')) {
|
||||||
if (input.value.length > 0) {
|
if (input.value.length > 0) {
|
||||||
@ -30,18 +45,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
input.addEventListener('blur', function() {
|
|
||||||
if (input.value.length < 1) {
|
|
||||||
label.classList.remove('reactive-label--small');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.from(document.querySelectorAll('.reactive-label')).forEach(function(label) {
|
|
||||||
var input = document.querySelector('#' + label.getAttribute('for'));
|
|
||||||
window.utils.reactiveInputLabel(input, label);
|
|
||||||
});
|
|
||||||
|
|
||||||
// registers input-listener for each element in <elements> (array) and
|
// registers input-listener for each element in <elements> (array) and
|
||||||
// enables <button> if <fn> for these elements returns true
|
// enables <button> if <fn> for these elements returns true
|
||||||
window.utils.reactiveButton = function(elements, button, fn) {
|
window.utils.reactiveButton = function(elements, button, fn) {
|
||||||
@ -65,6 +70,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
|
Array.from(document.querySelectorAll('.reactive-label')).forEach(function(label) {
|
||||||
|
var input = document.querySelector('#' + label.getAttribute('for'));
|
||||||
|
// dont be reactive if input is date, or checkbox/radioox
|
||||||
|
var type = input.getAttribute('type');
|
||||||
|
var badinputs = ['date', 'checkbox', 'radio', 'hidden'];
|
||||||
|
var badregex = RegExp(badinputs.join('|'));
|
||||||
|
window.utils.reactiveInputLabel(input, label, badregex.test(type));
|
||||||
|
});
|
||||||
|
|
||||||
// auto reactiveButton submit-buttons with required fields
|
// auto reactiveButton submit-buttons with required fields
|
||||||
var forms = document.querySelectorAll('form');
|
var forms = document.querySelectorAll('form');
|
||||||
|
|||||||
@ -47,7 +47,6 @@ input[type="submit"][disabled],
|
|||||||
input[type="button"][disabled],
|
input[type="button"][disabled],
|
||||||
button[disabled] {
|
button[disabled] {
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
border: 1px solid transparent;
|
|
||||||
background-color: var(--greybase);
|
background-color: var(--greybase);
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
@ -93,11 +92,7 @@ textarea:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-group--valid {
|
.form-group--valid {
|
||||||
border-left: 8px solid var(--lightbase);
|
border-left: 8px solid #2dcc35;
|
||||||
}
|
|
||||||
|
|
||||||
.form-group--optional {
|
|
||||||
border-left: 8px solid var(--greybase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group--has-error {
|
.form-group--has-error {
|
||||||
@ -221,7 +216,7 @@ input[type="checkbox"]:checked::after {
|
|||||||
/* REACTIVE LABELS */
|
/* REACTIVE LABELS */
|
||||||
.reactive-label {
|
.reactive-label {
|
||||||
cursor: text;
|
cursor: text;
|
||||||
color: #888;
|
color: var(--fontsec);
|
||||||
transform: translate(0, 0);
|
transform: translate(0, 0);
|
||||||
transition: all .1s;
|
transition: all .1s;
|
||||||
}
|
}
|
||||||
@ -229,14 +224,20 @@ input[type="checkbox"]:checked::after {
|
|||||||
cursor: default;
|
cursor: default;
|
||||||
color: var(--fontbase);
|
color: var(--fontbase);
|
||||||
}
|
}
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 999px) {
|
||||||
|
.form-group {
|
||||||
|
grid-template-rows: 30px auto;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
align-items: baseline;
|
||||||
|
margin-top: 17px;
|
||||||
|
}
|
||||||
.reactive-label {
|
.reactive-label {
|
||||||
position: absolute;
|
position: relative;
|
||||||
left: 4px;
|
transform: translate(2px, 30px);
|
||||||
top: 8px;
|
|
||||||
}
|
}
|
||||||
.reactive-label--small {
|
.reactive-label--small {
|
||||||
transform: translate(0, -120%);
|
transform: translate(2px, 0px);
|
||||||
font-size: 12px;
|
color: var(--fontsec);
|
||||||
|
/*font-size: 14px;*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user