diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-11 22:15:12 +0400 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-13 17:48:26 +0400 |
commit | 0b5e0e4c557a9cf8aad9a551ff71dc3699143895 (patch) | |
tree | 18baafe7ee83684ac7b78357cc73b93883fad2c8 /app | |
parent | e24589a165d8ed23aa8164f488f2de9f1b358668 (diff) |
Disable label submit button if any field is empty
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js.coffee | 29 | ||||
-rw-r--r-- | app/assets/javascripts/dispatcher.js.coffee | 2 | ||||
-rw-r--r-- | app/assets/javascripts/labels.js.coffee | 18 | ||||
-rw-r--r-- | app/views/projects/labels/_form.html.haml | 2 |
4 files changed, 48 insertions, 3 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 82a810b6551..9c53d3b4cc0 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -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() diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index ff68b520ad6..fa1e9aaa66f 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -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() diff --git a/app/assets/javascripts/labels.js.coffee b/app/assets/javascripts/labels.js.coffee new file mode 100644 index 00000000000..e6ab3f9ee12 --- /dev/null +++ b/app/assets/javascripts/labels.js.coffee @@ -0,0 +1,18 @@ +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 diff --git a/app/views/projects/labels/_form.html.haml b/app/views/projects/labels/_form.html.haml index 2a5c907febe..be7fddc65e7 100644 --- a/app/views/projects/labels/_form.html.haml +++ b/app/views/projects/labels/_form.html.haml @@ -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' |