Skip to content

Commit

Permalink
Escape js, fix dateranges being added twice because of unfortunate merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Dec 10, 2016
1 parent c40bb0f commit 9e78c42
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
13 changes: 0 additions & 13 deletions app/assets/javascripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ jQuery(function() {
});
});

$(document).on('turbolinks:load', function() {
$('#event-add-date-picker').bind('click', function() {
// insert our template to the ui and add a remove button
$(EVENT_DATE_PICKER_TEMPLATE)
.insertBefore(this)
.append(' <a style="float: none" class="close">&times;</a>')
.find('.close')
.click(function() {
$(this).parent('div').remove();
});
});
});

function addEventDatePicker() {
var picker = $('#event-add-date-picker');

Expand Down
4 changes: 2 additions & 2 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
<div class="col-lg-10" id="event-date-pickers">
<% def date_picker_template(start_date = Date.current, end_date = Date.current)
start_picker = text_field_tag "event[date_ranges_attributes][][start_date]", (I18n.l start_date),
class: 'form-control', :"data-datepicker" => 'true'
class: 'form-control', :"data-enable-datepicker" => 'true'
end_picker = text_field_tag "event[date_ranges_attributes][][end_date]", (I18n.l end_date),
class: 'form-control', :"data-datepicker" => 'true'
class: 'form-control', :"data-enable-datepicker" => 'true'

"<div>#{start_picker} #{t 'date_range.to'} #{end_picker} "+
"<a class=\"close\" onclick=\"javascript:removeEventDatePicker(event.target)\">&times;</a></div>"
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<script>
function enableDatepickers() {
$('[data-datepicker="true"]').datepicker({
language:"<%= I18n.locale %>",
format: "<%= I18n.t('date.formats.datepicker')%>",
$('[data-enable-datepicker="true"]').datepicker({
language:"<%= j I18n.locale.to_s %>",
format: "<%= j I18n.t('date.formats.datepicker') %>",
});
}
$(document).bind('turbolinks:load', enableDatepickers);
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<% unless attr_name == :birth_date %>
<%= f.text_field attr_name, :class => 'form-control' %>
<% else %>
<%= f.text_field attr_name, :class => 'form-control', :"data-datepicker" => "true", value: (I18n.l @profile.public_send(attr_name) if @profile.public_send(attr_name)) %>
<%= f.text_field attr_name, :class => 'form-control', :"data-enable-datepicker" => "true", value: (I18n.l @profile.public_send(attr_name) if @profile.public_send(attr_name)) %>
<% end %>
<%=f.error_span(attr_name) %>
</div>
Expand Down

0 comments on commit 9e78c42

Please sign in to comment.