list authorities, display name label only if available, else display authority_hrn
[unfold.git] / portal / templates / registration_view.html
index 450575d..1f27d41 100644 (file)
       <div class="col-xs-6"><p class="form-hint">Enter your last name</p></div>
     </div>
     <div class="form-group">
-      <label for="auth_list" class="col-xs-2 control-label">Authority</label>
+      <label for="authority_hrn" class="col-xs-2 control-label">Authority</label>
       <div class="col-xs-4">
         <div class="ui-widget">
-            <input id="auth_list">
+            <input id="authority_hrn" name="authority_hrn" class="form-control" value="{{ authority_hrn }}" required>
         </div>
      </div>
       <div class="col-xs-6"><p class="form-hint">An authority responsible for vetting your account</p></div>
@@ -47,7 +47,6 @@
        TODO: Login should be suggested from user email or first/last name, and
        checked for existence. In addition, the full HRN should be shown to the
        user.
-       -->
     <div class="form-group">
       <label for="login" class="col-xs-2 control-label">Login</label>
       <div class="col-xs-4">
@@ -55,7 +54,8 @@
       </div>
       <div class="col-xs-6"><p class="form-hint">Enter your login</p></div>
     </div>
-    
+       -->
+
     <div class="form-group">
       <label for="email" class="col-xs-2 control-label">Email</label>
       <div class="col-xs-4">
@@ -108,15 +108,28 @@ jQuery(document).ready(function(){
     var availableTags = [
     {% if authorities %}
         {% for authority in authorities %}
-        {value:"{{ authority.authority_hrn }}",label:"{{authority.name}}"},
+            {% if authority.name %}
+                {value:"{{ authority.authority_hrn }}",label:"{{authority.name}}"},
+            {% else %}
+                {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"},
+            {% endif %}
         {% endfor %}    
     {% else %}
         {value:"",label:"No authority found !!!"}
     {% endif %}
     ];
-    $( "#auth_list" ).autocomplete({
+    jQuery( "#authority_hrn" ).autocomplete({
       source: availableTags,
-      select: function( event, ui ) {console.log(jQuery(this))}
+      minLength: 0,
+      change: function (event, ui) {
+          if(!ui.item){
+              //http://api.jqueryui.com/autocomplete/#event-change -
+              // The item selected from the menu, if any. Otherwise the property is null
+              //so clear the item for force selection
+              jQuery("#authority_hrn").val("");
+          }
+      }
+      //select: function( event, ui ) {console.log(jQuery(this))}
     });
 });
 </script>