Files
nairobi/app/assets/javascripts/forms.js.coffee
Javi Martín 789476e6ab Synchronize percentage for new progress bars
According to the HTML specification:

> The default value is the minimum plus half the difference between the
> minimum and the maximum, unless the maximum is less than the minimum,
> in which case the default value is the minimum.

So for new progress bars, we had a numeric value of `nil` and a range
value of `50`, meaning the input fields weren't in sync.

Manually triggering the event on the progress, while not an ideal
solution (ideally we would be able to define `0` as default), sets the
value of the numeric field.
2019-01-18 14:17:53 +01:00

52 lines
1.3 KiB
CoffeeScript

App.Forms =
disableEnter: ->
$('form.js-enter-disabled').on('keyup keypress', (event) ->
if event.which == 13
e.preventDefault()
)
submitOnChange: ->
$('.js-submit-on-change').unbind('change').on('change', ->
$(this).closest('form').submit()
false
)
toggleLink: ->
$('.js-toggle-link').unbind('click').on('click', ->
$($(this).data('toggle-selector')).toggle("down")
if $(this).data('toggle-text') isnt undefined
toggle_txt = $(this).text()
$(this).text( $(this).data('toggle-text') )
$(this).data('toggle-text', toggle_txt)
false
)
synchronizeInputs: ->
$("[name='progress_bar[percentage]']").on
input: ->
$("[name='#{this.name}']").val($(this).val())
$("[name='progress_bar[percentage]'][type='range']").trigger("input")
hideOrShowFieldsAfterSelection: ->
$("[name='progress_bar[kind]']").on
change: ->
title_field = $("[name^='progress_bar'][name$='[title]']").parent()
if this.value == "primary"
title_field.hide()
else
title_field.show()
$("[name='progress_bar[kind]']").change()
initialize: ->
App.Forms.disableEnter()
App.Forms.submitOnChange()
App.Forms.toggleLink()
App.Forms.synchronizeInputs()
App.Forms.hideOrShowFieldsAfterSelection()
false