Auto convert title and note field to text when pasting from clipboard.

This commit is contained in:
BoHung Chiu 2022-07-20 22:40:46 +08:00
parent 39be2dd0e9
commit a956408459
1 changed files with 7 additions and 3 deletions

View File

@ -62,7 +62,7 @@
<%= f.fields_for :title_translations, f.object do |f| %>
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="title_translations_<%= locale %>">
<% title = f.object.title(locale) %>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment"><%= title.to_s.html_safe %></div>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment preserve_input_text"><%= title.to_s.html_safe %></div>
<%= hidden_field_tag "#{f.object_name}[#{locale}]", title %>
</div>
<% end %>
@ -83,7 +83,7 @@
<%= f.fields_for :note_translations, f.object do |f| %>
<div class="tab-pane fade <%= ( i == 0 ) ? "active in" : '' %>" id="note_translations_<%= locale %>">
<% note = f.object.note(locale) %>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment"><%= note.to_s.html_safe %></div>
<div data-ph="<%= t('calendar.press_enter') %>" contenteditable="true" class="calendar-comment preserve_input_text"><%= note.to_s.html_safe %></div>
<%= hidden_field_tag "#{f.object_name}[#{locale}]", note %>
</div>
<% end %>
@ -283,6 +283,10 @@
if (year != '' && month != '' && day != ''){
parent_div.find('input[type="hidden"]').eq(-1).val(year+'-'+month+'-'+day)
}
})
});
$('.preserve_input_text').off('paste').on('paste',function(e){
$(this).html(($('<div></div>').append(e.originalEvent.clipboardData.getData('text/plain')).text()));
e.preventDefault();
});
})
</script>