summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruran <uran@zeoalliance.com>2014-08-27 13:12:42 +0300
committeryglukhov <yuriy.glukhov@gmail.com>2014-12-23 16:04:39 +0200
commitb34e83d261f30549062ee7c8b9e25f632bbcf163 (patch)
treeea15c995b7944384278ff0746e0425bc6b11cd70
parent554719d985916d9f49f70b577382ab3a6da7eb7f (diff)
downloadgitlab-ce-b34e83d261f30549062ee7c8b9e25f632bbcf163.tar.gz
Corrected validation of 'Create branch' and 'Create tag' buttons
-rw-r--r--app/assets/javascripts/application.js.coffee24
-rw-r--r--app/views/projects/branches/new.html.haml3
-rw-r--r--app/views/projects/tags/new.html.haml3
3 files changed, 13 insertions, 17 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee
index 4cda8b75d8e..2ff64efdc5b 100644
--- a/app/assets/javascripts/application.js.coffee
+++ b/app/assets/javascripts/application.js.coffee
@@ -76,24 +76,18 @@ window.disableButtonIfEmptyField = (field_selector, button_selector) ->
# Disable button if any input field with given selector is empty
window.disableButtonIfAnyEmptyField = (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
+ updateButtons = ->
+ filled = true
form.find('input').filter(form_selector).each ->
- empty = true if rstrip($(this).val()) is ""
+ filled = rstrip($(this).val()) != "" || !$(this).attr('required')
- if empty
- closest_submit.disable()
- else
+ if filled
closest_submit.enable()
+ else
+ closest_submit.disable()
+
+ updateButtons()
+ form.keyup(updateButtons)
window.sanitize = (str) ->
return str.replace(/<(?:.|\n)*?>/gm, '')
diff --git a/app/views/projects/branches/new.html.haml b/app/views/projects/branches/new.html.haml
index a6623240da1..2719bcc33bc 100644
--- a/app/views/projects/branches/new.html.haml
+++ b/app/views/projects/branches/new.html.haml
@@ -5,7 +5,7 @@
%h3.page-title
%i.fa.fa-code-fork
New branch
-= form_tag project_branches_path, method: :post, class: "form-horizontal" do
+= form_tag project_branches_path, method: :post, id: "new-branch-form", class: "form-horizontal" do
.form-group
= label_tag :branch_name, 'Name for new branch', class: 'control-label'
.col-sm-10
@@ -19,6 +19,7 @@
= link_to 'Cancel', project_branches_path(@project), class: 'btn btn-cancel'
:javascript
+ disableButtonIfAnyEmptyField($("#new-branch-form"), ".form-control", ".btn-create");
var availableTags = #{@project.repository.ref_names.to_json};
$("#ref").autocomplete({
diff --git a/app/views/projects/tags/new.html.haml b/app/views/projects/tags/new.html.haml
index ad7ff8d3db8..289c52a2e3f 100644
--- a/app/views/projects/tags/new.html.haml
+++ b/app/views/projects/tags/new.html.haml
@@ -5,7 +5,7 @@
%h3.page-title
%i.fa.fa-code-fork
New tag
-= form_tag project_tags_path, method: :post, class: "form-horizontal" do
+= form_tag project_tags_path, method: :post, id: "new-tag-form", class: "form-horizontal" do
.form-group
= label_tag :tag_name, 'Name for new tag', class: 'control-label'
.col-sm-10
@@ -25,6 +25,7 @@
= link_to 'Cancel', project_tags_path(@project), class: 'btn btn-cancel'
:javascript
+ disableButtonIfAnyEmptyField($("#new-tag-form"), ".form-control", ".btn-create");
var availableTags = #{@project.repository.ref_names.to_json};
$("#ref").autocomplete({