Commit 0b5e0e4c authored by Robert Schilling's avatar Robert Schilling

Disable label submit button if any field is empty

parent e24589a1
......@@ -53,15 +53,40 @@ window.split = (val) ->
window.extractLast = (term) ->
return split( term ).pop()
window.rstrip = (val) ->
return val.replace(/\s+$/, '')
# Disable button if text field is empty
window.disableButtonIfEmptyField = (field_selector, button_selector) ->
field = $(field_selector)
closest_submit = field.closest("form").find(button_selector)
closest_submit.disable() if field.val().replace(/\s+$/, "") is ""
closest_submit.disable() if rstrip(field.val()) is ""
field.on "input", ->
if $(@).val().replace(/\s+$/, "") is ""
if rstrip($(@).val()) is ""
closest_submit.disable()
else
closest_submit.enable()
# Disable button if any input field with given selector is empty
window.disableButtonIfEmptyField = (form, form_selector, button_selector) ->
closest_submit = form.find(button_selector)
empty = false
form.find('input').filter(form_selector).each ->
empty = true if rstrip($(this).val()) is ""
if empty
closest_submit.disable()
else
closest_submit.enable()
form.keyup ->
empty = false
form.find('input').filter(form_selector).each ->
empty = true if rstrip($(this).val()) is ""
if empty
closest_submit.disable()
else
closest_submit.enable()
......
......@@ -42,6 +42,8 @@ class Dispatcher
new TreeView()
when 'projects:blob:show'
new BlobView()
when 'projects:labels:new'
new Labels()
switch path.first()
when 'admin' then new Admin()
......
class Labels
constructor: ->
# find the form
form = $('.label-form')
@setupLabelForm(form)
###
General note form setup.
deactivates the submit button when text is empty
hides the preview button when text is empty
setup GFM auto complete
show the form
###
setupLabelForm: (form) ->
disableButtonIfEmptyField form, '.form-control', form.find('.js-save-button')
@Labels = Labels
......@@ -28,7 +28,7 @@
 
.form-actions
= f.submit 'Save', class: 'btn btn-save'
= f.submit 'Save', class: 'btn btn-save js-save-button'
= link_to "Cancel", project_labels_path(@project), class: 'btn btn-cancel'
......
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