From e884acd37b2eafe324b7e829222a5a01748c4f4a Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Fri, 20 Apr 2018 13:24:58 +0200
Subject: [PATCH] Hide interface name in create host form

The interface name doesn't need to be displayed in the form as we force
it to the hostname.

We set the interface name to the hostname when submitting the form.
This fixes the copy/paste issue with the mouse that didn't trigger the
keyup event.

JIRA INFRA-287
---
 app/static/js/hosts.js                 | 12 +++++-------
 app/templates/network/create_host.html |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/app/static/js/hosts.js b/app/static/js/hosts.js
index 9ceee6d..96df16c 100644
--- a/app/static/js/hosts.js
+++ b/app/static/js/hosts.js
@@ -69,14 +69,12 @@ $(document).ready(function() {
     update_device_type_attributes();
   });
 
-  // Prefill interface name with hostname
-  $("#name").keyup(function(event) {
-    var hostname = $(this).val();
+  // The interface name field is hidden in the create host form
+  // because it should be forced to the hostname
+  // Do that when submitting the form
+  $("#hostForm").submit(function(event) {
+    var hostname = $("#name").val();
     $("#interface_name").val(hostname);
-    // If an invalid hostname was submitted, the interface name
-    // will be invalid as well
-    // Remove the invalid messages when starting typing a new name
-    $("#interface_name").removeClass("is-invalid");
   });
 
   // Fill MAC address on page load
diff --git a/app/templates/network/create_host.html b/app/templates/network/create_host.html
index 0f85476..f228a9d 100644
--- a/app/templates/network/create_host.html
+++ b/app/templates/network/create_host.html
@@ -6,13 +6,13 @@
 {% block hosts_main %}
   <form id="hostForm" method="POST">
     {{ form.hidden_tag() }}
+    {{ form.interface_name(type="hidden") }}
     {{ render_field(form.name, class_="text-lowercase") }}
     {{ render_field(form.device_type_id) }}
     {{ render_field(form.description) }}
     {{ render_field(form.item_id, disabled=True) }}
     {{ render_field(form.network_id) }}
     {{ render_field(form.ip) }}
-    {{ render_field(form.interface_name, class_="text-lowercase") }}
     {{ render_field(form.random_mac) }}
     {{ render_field(form.mac_address) }}
     {{ render_field(form.cnames_string) }}
-- 
GitLab