guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Add form validation.


From: Mathieu Othacehe
Subject: branch master updated: Add form validation.
Date: Fri, 12 Mar 2021 04:53:16 -0500

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch master
in repository guix-cuirass.

The following commit(s) were added to refs/heads/master by this push:
     new 8379c80  Add form validation.
8379c80 is described below

commit 8379c803dcc10558d406cedfd627322d6e6bf474
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Fri Mar 12 10:53:05 2021 +0100

    Add form validation.
---
 src/cuirass/templates.scm | 46 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index 80f506c..9fd4f08 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -299,7 +299,8 @@ the existing SPEC otherwise."
                                 (id "channel-name")
                                 (name "channel-name")
                                 (placeholder "name")
-                                (value ,name))))
+                                (value ,name)
+                                (required))))
                        (div (@ (class "col-sm-4"))
                             (input
                              (@ (type "text")
@@ -307,7 +308,8 @@ the existing SPEC otherwise."
                                 (id "channel-url")
                                 (name "channel-url")
                                 (placeholder "url")
-                                (value ,url))))
+                                (value ,url)
+                                (required))))
                        (div (@ (class "col-sm-2"))
                             (input
                              (@ (type "text")
@@ -315,7 +317,8 @@ the existing SPEC otherwise."
                                 (id "channel-branch")
                                 (name "channel-branch")
                                 (placeholder "branch")
-                                (value ,branch))))
+                                (value ,branch)
+                                (required))))
                        ,@(if first-row?
                              '((a (@ (class "btn btn-success add-channel")
                                       (href "#")
@@ -362,8 +365,36 @@ $('.add-channel').click(function() {
   });
   clone.appendTo('.channels');
 });
-})")
+var cbs = $('.system');
+cbs.change(function(){
+  if(cbs.is(':checked')) {
+    cbs.removeAttr('required');
+  } else {
+    cbs.attr('required', 'required');
+  }
+});
+var checked_cbs = $('.system:checkbox:checked').length;
+if (checked_cbs == 0) {
+  cbs.attr('required', 'required');
+}
+
+(function () {
+  'use strict'
+  var forms = document.querySelectorAll('.needs-validation')
+  Array.prototype.slice.call(forms)
+    .forEach(function (form) {
+      form.addEventListener('submit', function (event) {
+        if (!form.checkValidity()) {
+          event.preventDefault()
+          event.stopPropagation()
+        }
+        form.classList.add('was-validated')
+      }, false)
+    })
+})();
+});")
       (form (@ (id "add-specification")
+               (class "needs-validation")
                ,@(if spec
                      '((action "/admin/specification/edit"))
                      '((action "/admin/specification/add")))
@@ -380,7 +411,8 @@ $('.add-channel').click(function() {
                                 (value ,(or name ""))
                                 ,@(if spec
                                       '((readonly))
-                                      '())))))
+                                      '())
+                                (required)))))
             (div (@ (class "form-group row"))
                  (label (@ (for "build")
                            (class "col-sm-2 col-form-label"))
@@ -408,6 +440,8 @@ $('.add-channel').click(function() {
                           (class "form-control")
                           (id "priority")
                           (name "priority")
+                          (min 0)
+                          (max 9)
                           (value ,(or priority 9))))))
             (div (@ (class "form-group row"))
                  (label (@ (for "systems")
@@ -415,7 +449,7 @@ $('.add-channel').click(function() {
                         "Systems")
                  ,@(map (lambda (system)
                           `(div (@ (class "form-check form-check-inline"))
-                                (input (@ (class "form-check-input")
+                                (input (@ (class "form-check-input system")
                                           (type "checkbox")
                                           (id ,system)
                                           (name ,system)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]