Commit 7f1633e2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #7615 from yglukhov/new-branch-submit-button-validation

Validation of 'Create branch' and 'Create tag' buttons
parents 7d1e6f15 b34e83d2
......@@ -74,24 +74,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
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()
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()
closest_submit.disable()
updateButtons()
form.keyup(updateButtons)
window.sanitize = (str) ->
return str.replace(/<(?:.|\n)*?>/gm, '')
......
......@@ -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({
......
......@@ -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({
......
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