content_edit.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. $(function () {
  2. $("#form-content-edit").validate({
  3. rules: {
  4. title: {
  5. required: true,
  6. minlength: 1,
  7. maxlength: 64
  8. },
  9. navigation_id: {
  10. required: true,
  11. },
  12. content: {
  13. required: true,
  14. },
  15. resource: {
  16. // required: true,
  17. minlength: 1,
  18. maxlength: 64
  19. },
  20. sort: {
  21. required: true,
  22. min: 0,
  23. max: 10000,
  24. digits: true
  25. },
  26. brief: {
  27. // // required: true,
  28. // maxlength: 100
  29. }
  30. },
  31. onkeyup:false,
  32. focusCleanup:true,
  33. success:"valid",
  34. submitHandler:function(form){
  35. //如果摘要没填写,取正文前50个字
  36. //2018-07-06 不需要自动加摘要
  37. /*if($.trim($("#brief").val())==""){
  38. var content = $("#content").val();
  39. if($.trim(content)!=""){
  40. var defaultAbstract = "";
  41. //去除标签
  42. var cleanContent = content.replace(/<\/?.+?>/g,""); //去标签
  43. cleanContent = cleanContent.replace(/(^\s+)|(\s+$)/g,""); //去空格
  44. cleanContent = cleanContent.replace(/(\r)|(\n)/g,""); //去回车
  45. cleanContent = cleanContent.replace(/&nbsp;/ig,''); //去掉&nbsp;
  46. if(cleanContent.length>50){
  47. defaultAbstract = cleanContent.substring(0,50);
  48. defaultAbstract += "...";
  49. }else{
  50. defaultAbstract = cleanContent;
  51. }
  52. $("#brief").val(defaultAbstract);
  53. }
  54. }*/
  55. $(form).ajaxSubmit({
  56. type: 'PUT',
  57. url: pagePath+"/government/content/update/"+$("#content_id").val(),
  58. dataType:"json",
  59. success: function(data){
  60. if(data.status == "success"){
  61. succeedMessage(data.message);
  62. setTimeClose();
  63. }else {
  64. errorMessage(data.message);
  65. }
  66. }
  67. });
  68. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  69. },
  70. errorPlacement: function(error, element) {
  71. if(element.attr('id') == 'content'){
  72. error.addClass(' label_error')
  73. }
  74. error.appendTo(element.parent());
  75. }
  76. });
  77. });