Skip to content

Commit

Permalink
fixed FireFox event.preventDefault() refresh bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mindovermiles262 committed Nov 19, 2017
1 parent cc62d5b commit 0beeba9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
24 changes: 13 additions & 11 deletions app/assets/javascripts/forms.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$( document ).on('turbolinks:load', function() {
// Removes Sample fields from Projects Form
$('form').on('click', '.destroy_fields', function() {
$('form').on('click', '.destroy_fields', function(event) {
$(this).prev('input[type=hidden]').val('1')
$(this).closest('.fieldset').hide()
event.preventDefault()
})

// Adds Test fields to Samples form
$('form').on('click', '.add_fields', function() {
$('form').on('click', '.add_fields', function(event) {
time = new Date().getTime()
regex = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regex, time))
Expand All @@ -22,19 +22,21 @@ $( document ).on('turbolinks:load', function() {
})

// Remove Table Rows from Batch
$('table').on('click', '.destroy_row', function() {
$('#available_tests_section').show()
$('table').on('click', '.destroy_row', function(event) {
$('#available_tests_section').show();
var row = $(this).parents('tr:first');
$(this).prev('input[type=hidden]').val('nil')
$('#append_to_unbatched').append(row)
$(row).find('a').attr('class', 'add_test_to_batch')
$(row).find('i').attr("aria-hidden", "true")
$(row).find('i').attr("class", "fa fa-plus")
event.preventDefault()
$(this).prev('input[type=hidden]').val('nil');
$('#append_to_unbatched').append(row);
$(row).find('a').attr('class', 'add_test_to_batch');
$(row).find('i').attr("aria-hidden", "true");
$(row).find('i').attr("class", "fa fa-plus");
event.preventDefault();
console.log("return false")
return false;
})

// Add Table Rows to Batch
$('table').on('click', '#add_test', function() {
$('table').on('click', '#add_test', function(event) {
var row = $(this).parents('tr:first');
$('#append_to_batch').append(row)
$(row).find('a').attr('class', 'destroy_row')
Expand Down
10 changes: 3 additions & 7 deletions app/views/batches/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="columns">
<div class="column is-10 is-offset-1">
<%= form_for @batch do |batch| %>
<%= form_for @batch, remote: true do |batch| %>
<table class="table is-striped is-fullwidth">
<thead>
<tr>
Expand All @@ -14,7 +14,7 @@
</tr>
</thead>
<tbody id='append_to_batch'>
<%= batch.fields_for :tests, remote: true do |test| %>
<%= batch.fields_for :tests do |test| %>
<tr>
<td><%= test.object.sample.project.user.company %></td>
<td><%= test.object.sample.project.description %></td>
Expand All @@ -39,11 +39,7 @@
<%= p.label :pipet_id, "Pipet", class: 'field-label' %>
</div>
<div class="select field-control">
<%=
p.select :pipet_id, options_for_select(@pipets, selected: @selected),
{include_blank: true},
{}
%>
<%= p.select :pipet_id, options_for_select(@pipets, selected: @selected) %>
</div>
<% end %>
</div>
Expand Down
1 change: 0 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
t.string "reference_method"
t.integer "turn_around_time"
t.integer "detection_limit"
t.integer "batch_id"
t.string "unit"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down

0 comments on commit 0beeba9

Please sign in to comment.