Disable submit button until all input fields are filled in.
[arvados.git] / apps / workbench / app / views / users / _setup_popup.html.erb
1   <div class="modal-body">
2     <% uuid = @object.uuid %>
3     <% disable_email =  @object.uuid? %>
4     <% identity_url_prefix = @current_selections[:identity_url_prefix] %>
5     <% selected_repo = @current_selections[:repo_name] %>
6     <% selected_vm = @current_selections[:vm_uuid] %>
7     
8     <%= form_tag setup_user_url(id: uuid), {id: 'setup_form', name: 'setup_form', method: 'get', class: 'form-search', remote: true, onSubmit: "validate(); return false;"} do %>    
9       <div>
10         <table><tbody>
11           <tr>
12             <% if disable_email %>
13               <td> Email </td>
14               <td> <input id="email" maxlength="250" name="email" type="text" value="<%=@object.email%>" disabled=<%=disable_email%> > </td>
15             <% else %>
16               <td> Email </td>
17               <td> <input id="email" maxlength="250" name="email" type="text" > </td>
18             <% end %>
19           </tr>
20           <tr>
21             <% if disable_email %>
22               <td> Identity URL Prefix </td>
23               <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" value="<%=identity_url_prefix%>" disabled=<%=disable_email%> > </td>
24             <% else %>
25               <td> Openid Prefix </td>
26               <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" value="https://www.google.com/accounts/o8/id"> </td>
27             <% end %>
28           </tr>
29           <tr>
30             <td> Repository Name </td>
31             <td> <input id="repo_name" maxlength="250" name="repo_name" type="text" value="<%=selected_repo%>">
32           </tr>
33           <tr>
34             <td> Virtual Machine </td>
35             <td>
36               <select name="vm_uuid">
37                 <% @vms.each do |vm| %>
38                   <% if selected_vm == vm.uuid %>
39                     <option value=<%=vm.uuid%> selected> <%=vm.hostname%> </option>
40                   <% else %> 
41                     <option value=<%=vm.uuid%> > <%=vm.hostname%> </option>
42                   <% end %>
43                 <% end %>
44               </select>
45             </td>
46           </tr>
47         </tbody></table>
48       </div>
49       <div align="left">
50         <button type="submit" id="register" class="btn btn-primary" autofocus>Submit</button>
51         <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Cancel</button>
52       </div>
53     <% end %>
54   </div>
55
56 <script>
57   var $input = $('input:text'),
58   $register = $('#register');    
59   $register.attr('disabled', true);
60
61   $input.keyup(function() {
62     var trigger = false;
63     $input.each(function() {
64         if (!$(this).val()) {
65             trigger = true;
66         }
67     });
68     trigger ? $register.attr('disabled', true) : $register.removeAttr('disabled');
69   });
70 </script>