Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix selectize bug #212

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions app/assets/javascripts/expenses.js.coffee
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
$(document).on 'turbolinks:load', ->
$(document).on 'ready, turbolinks:load', ->
# scope to single controller
return unless $('body.expenses').length or
$('body.expenses_reviews').length

expense_kind_input = $('#expense_kind')
order_input = $('#expense_order_id')
order_selectized_input = $('#expense_order_id-selectized')
order_form_group = order_input.closest('.form-group')
receipt_input = $('#expense_receipt')
warning_popup = $('#file_warning')

toggle_project_display = () ->
kind = $('#expense_kind :selected')
order = $('#expense_order_id')
form_group = order.closest('.form-group')
input = form_group.find('input')

kind.each ->
if this.value == 'project'
if order[0].textContent and not input[0].value
input[0].value = ' '

form_group.show()
input.attr('required', 'required')
else
form_group.hide()
input.removeAttr('required')

if expense_kind_input.val() == 'project'
# if order_input.value and not order_selectized_input.value
# input[0].value = ' '

order_form_group.show()
order_selectized_input.attr('disabled', false)
else
order_form_group.hide()
order_selectized_input.attr('disabled', true)

check_file_type = (initial = false) ->
input = $('#expense_receipt')[0]
files = input.files
warning = $('#file_warning')
warning_popup.addClass('hidden')

warning.addClass('hidden')
return unless files.length > 0
return if /^image/.test(files[0].type)
return unless receipt_input[0].files.length > 0
return if /^image/.test(receipt_input[0].files[0].type)

warning.removeClass('hidden') unless initial
input.value = ''
warning_popup.removeClass('hidden')

check_file_type(true)
toggle_project_display()

$('#expense_kind').change (e) ->
expense_kind_input.change (e) ->
toggle_project_display()

$('#expense_receipt').change (e) ->
receipt_input.change (e) ->
check_file_type()