diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-04-13 18:19:41 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-04-13 18:19:41 -0400 |
| commit | d45f617dc74a07beb352d04537d47a77193f487f (patch) | |
| tree | bf87a7f2b1bba238588194b0b29c26e6bd6b9f24 /themes/okadmin/public/js/app.js | |
| parent | 3ac36830841a51f3d3de63f5df849a4bb84b948d (diff) | |
hide id field
Diffstat (limited to 'themes/okadmin/public/js/app.js')
| -rw-r--r-- | themes/okadmin/public/js/app.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 91a8e1a..009fe4c 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -51,13 +51,18 @@ var OKAdmin = function(){ // fix post indexing in list-driven inputs $(".main.resource form").submit(function(e){ - var $id = $("[name=id]") - if ($id.length && ! $id.val()) { - alert("Please enter an ID") - $id.focus() + var $id = $("[name=id]"), $title = $("[name=title]") + + if ($title.length && ! $title.val()) { + alert("Please enter a title") + $title.focus() e.preventDefault() return } + + var slug = slugify( $title.val() ) + $id.val( slug ) + $(".image-element").each(function(index){ $(this).find("input,textarea").each(function(){ var field = $(this).attr("name").replace(/\[[0-9]*\]/, "[" + index + "]") @@ -129,3 +134,6 @@ var OKAdmin = function(){ $(function(){ window.app = new OKAdmin () }) + + +function slugify (s){ return (s || "").toLowerCase().replace(/\s/g,"-").replace(/[^-_a-zA-Z0-9]/g, '-').replace(/-+/g,"-") } |
