From 97e74c5bde3269d4760b55971e7c06b42679f422 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Sat, 7 Jan 2012 12:53:01 +0200 Subject: [PATCH] Auto-populate the path and code on the name input's onchange event to the sluggified version of name --- app/views/projects/_form.html.haml | 12 ++++++------ app/views/projects/new.html.haml | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 788c2b46..2fc6f9d9 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -58,14 +58,14 @@ = link_to 'Remove', @project, :confirm => 'Are you sure?', :method => :delete, :class => "red-button" -:javascript - $('.new_project, .edit_project').bind('ajax:before', function() { - $(this).find(".form_content").hide(); - $('.ajax_loader').show(); - }); - :javascript $(function(){ + $('.new_project, .edit_project').bind('ajax:before', function() { + $(this).find(".form_content").hide(); + $('.ajax_loader').show(); + }); + taggifyForm(); + $('form #project_default_branch').chosen(); }) diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 1678ba5d..02ddc683 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -8,3 +8,16 @@ %div.clear = render 'form' + +:javascript + $(function(){ + $("#project_name").change(function(){ + var slug = slugify($(this).val()); + $("#project_code").val(slug); + $("#project_path").val(slug); + }); + }); + + function slugify(text) { + return text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase(); + }