Commit 04ad197b authored by Robert Schilling's avatar Robert Schilling

Trigger an update of save button if user pressed a preview color

parent b9519c83
...@@ -59,18 +59,18 @@ window.rstrip = (val) -> ...@@ -59,18 +59,18 @@ window.rstrip = (val) ->
# Disable button if text field is empty # Disable button if text field is empty
window.disableButtonIfEmptyField = (field_selector, button_selector) -> window.disableButtonIfEmptyField = (field_selector, button_selector) ->
field = $(field_selector) field = $(field_selector)
closest_submit = field.closest("form").find(button_selector) closest_submit = field.closest('form').find(button_selector)
closest_submit.disable() if rstrip(field.val()) is "" closest_submit.disable() if rstrip(field.val()) is ""
field.on "input", -> field.on 'input', ->
if rstrip($(@).val()) is "" if rstrip($(@).val()) is ""
closest_submit.disable() closest_submit.disable()
else else
closest_submit.enable() closest_submit.enable()
# Disable button if any input field with given selector is empty # Disable button if any input field with given selector is empty
window.disableButtonIfEmptyField = (form, form_selector, button_selector) -> window.disableButtonIfAnyEmptyField = (form, form_selector, button_selector) ->
closest_submit = form.find(button_selector) closest_submit = form.find(button_selector)
empty = false empty = false
form.find('input').filter(form_selector).each -> form.find('input').filter(form_selector).each ->
......
...@@ -16,7 +16,7 @@ class Labels ...@@ -16,7 +16,7 @@ class Labels
# Initializes the form to disable the save button if no color or title is entered # Initializes the form to disable the save button if no color or title is entered
setupLabelForm: (form) -> setupLabelForm: (form) ->
disableButtonIfEmptyField form, '.form-control', form.find('.js-save-button') disableButtonIfAnyEmptyField form, '.form-control', form.find('.js-save-button')
# Updates the the preview color with the hex-color input # Updates the the preview color with the hex-color input
updateColorPreview: => updateColorPreview: =>
...@@ -28,6 +28,8 @@ class Labels ...@@ -28,6 +28,8 @@ class Labels
color = $(e.currentTarget).data('color') color = $(e.currentTarget).data('color')
$('input#label_color').val(color) $('input#label_color').val(color)
@updateColorPreview() @updateColorPreview()
# Notify the form, that color has changed
$('.label-form').trigger('keyup')
e.preventDefault() e.preventDefault()
@Labels = Labels @Labels = Labels
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment