gitlab-org--gitlab-foss/app/assets/javascripts/wikis.js.coffee
Jeroen van Baarsen b16aad9dd1 Validate wiki page creation
**What does this do?**
It adds validation to the creation of a wiki page, that way the user gets real
feedback instead of just a 404 page if the name of the wiki page was invalid

**Why is this needed?**
There are a lot of characters that are not allowed in the creation of a wiki
page, there is even a small text that is saying: Please don't use spaces.
Although we have that text there, we don't actually validate on this. This
commit adds validation on the title and gives the user actual feedback.

**What issues does this fix?**
Fixes http://github.com/gitlabhq/gitlabhq/issues/5357
Fixes https://github.com/gitlabhq/gitlabhq/issues/8565
Fixes https://github.com/gitlabhq/gitlabhq/issues/3913
Fixes https://github.com/gitlabhq/gitlabhq/issues/8166

Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
2015-05-26 19:01:11 +02:00

17 lines
526 B
CoffeeScript

class @Wikis
constructor: ->
$('.build-new-wiki').bind "click", (e) ->
$('[data-error~=slug]').addClass("hidden")
$('p.hint').show()
field = $('#new_wiki_path')
valid_slug_pattern = /^[\w\/-]+$/
slug = field.val()
if slug.match valid_slug_pattern
path = field.attr('data-wikis-path')
if(slug.length > 0)
location.href = path + "/" + slug
else
e.preventDefault()
$('p.hint').hide()
$('[data-error~=slug]').removeClass("hidden")