Question

I have a form in my rails app that allows a user to upload a CSV file.

There is checkmark box under the file field that has to do with an option they can enable. I would like to show a js alert window to confirm the checkbox selection if a user checks the box and submits. How could I accomplish this?

My form looks like this:

<%= form_tag({action: :import}, multipart: true, class: "form-inline") do %>
  <%= label_tag(:uploaded_file, "Choose a CSV file to upload:") %>
  <%= file_field_tag(:uploaded_file, class: "input-file") %>
  <%= submit_tag("Upload", class: "btn btn-primary") %>
  <%= button_tag("Cancel", type: 'reset', class: "") %>
  <br>
  <br>
  <label class="checkbox">Override import conflicts?</label>
  <%= check_box_tag "override", "true", false, class: "checkbox" %>
<% end %> 
Was it helpful?

Solution

First providing an id for the check box

<label class="checkbox" id="chkid">Override import conflicts?</label>
 <%= check_box_tag "override", "true", false, class: "checkbox" %>

and by using JS prototype like

function confirm()
{
if ($F('chkid').checked == false) 
      {
           "Please Select Check box\n";
       }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top