diff --git a/templates/widgets/form.julius b/templates/widgets/form.julius index 150ec639f..3efa02d9f 100644 --- a/templates/widgets/form.julius +++ b/templates/widgets/form.julius @@ -8,6 +8,11 @@ document.addEventListener('DOMContentLoaded', function() { window.utils.reactiveInputLabel = function(input, label) { if (input.value.length > 0) { label.classList.add('reactive-label--small'); + if (label.parentElement.classList.contains('form-group')) { + label.parentElement.classList.add('form-group--valid'); + } + } else { + label.parentElement.classList.remove('form-group--valid'); } input.addEventListener('focus', function() { label.classList.add('reactive-label--small'); @@ -16,6 +21,15 @@ document.addEventListener('DOMContentLoaded', function() { label.classList.add('reactive-label--small'); input.focus(); }); + input.addEventListener('input', function() { + if (label.parentElement.classList.contains('form-group')) { + if (input.value.length > 0) { + label.parentElement.classList.add('form-group--valid'); + } else { + label.parentElement.classList.remove('form-group--valid'); + } + } + }); input.addEventListener('blur', function() { if (input.value.length < 1) { label.classList.remove('reactive-label--small'); @@ -57,15 +71,17 @@ document.addEventListener('DOMContentLoaded', function() { Array.from(forms).forEach(function(form) { var requireds = form.querySelectorAll('[required]'); var submitBtn = form.querySelector('[type=submit]'); - window.utils.reactiveButton(Array.from(requireds), submitBtn, function(inputs) { - var done = true; - inputs.forEach(function(inp) { - var len = inp.value.trim().length; - if (done && len === 0) { - done = false; - } + if (submitBtn && requireds) { + window.utils.reactiveButton(Array.from(requireds), submitBtn, function(inputs) { + var done = true; + inputs.forEach(function(inp) { + var len = inp.value.trim().length; + if (done && len === 0) { + done = false; + } + }); + return done; }); - return done; - }); + } }); }); diff --git a/templates/widgets/form.lucius b/templates/widgets/form.lucius index 8b75f2921..fc75dcfd2 100644 --- a/templates/widgets/form.lucius +++ b/templates/widgets/form.lucius @@ -89,6 +89,10 @@ textarea:focus { } .form-group--required { + border-left: 8px solid var(--lighterbase); +} + +.form-group--valid { border-left: 8px solid var(--lightbase); }