edit.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <style>
  2. .nav-title{
  3. display: none;
  4. }
  5. </style>
  6. <div style="margin:50px auto;width: 400px;">
  7. <form class="layui-form" action="" method="post" >
  8. <div class="layui-form-item">
  9. <label class="layui-form-label">选择分组</label>
  10. <div class="layui-input-inline">
  11. <select name="group_id" lay-verify="required" lay-search="" style="width: 100%">
  12. <option value="">请选择分组</option>
  13. {{range $index,$elem := .Groups}}
  14. <option value="{{$elem.id}}" {{if eq $elem.id $.Source.group_id}} selected {{end}}>{{$elem.group_name}}</option>
  15. {{end}}
  16. </select>
  17. </div>
  18. <div class="layui-form-mid layui-word-aux">*</div>
  19. </div>
  20. <div class="layui-form-item">
  21. <label class="layui-form-label">资源名称</label>
  22. <div class="layui-input-inline">
  23. <input type="text" name="source_name" id="source_name" lay-verify="required" autocomplete="off" placeholder="资源名称" class="layui-input" value="{{.Source.source_name}}">
  24. </div>
  25. <div class="layui-form-mid layui-word-aux">*</div>
  26. </div>
  27. <input type="hidden" id="id" name="id" value="{{.Source.id}}">
  28. <div class="layui-form-item">
  29. <div class="layui-input-block">
  30. <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
  31. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  32. </div>
  33. </div>
  34. </form>
  35. </div>
  36. <script>
  37. var $;
  38. layui.config({
  39. base : "js/"
  40. }).use(['form','element','layer','jquery'],function(){
  41. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  42. var $ = layui.jquery;
  43. form.on('submit(sub)', function(data){
  44. var form_data = data.field;
  45. $.post('{{urlfor "ApiSourceController.AjaxSave"}}', form_data, function (out) {
  46. if (out.status == 0) {
  47. layer.msg("操作成功",{icon: 1},function () {
  48. window.parent.layer.closeAll();
  49. window.parent.location.reload();
  50. })
  51. } else {
  52. layer.msg(out.message)
  53. }
  54. }, "json");
  55. return false;
  56. });
  57. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  58. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  59. form.render();
  60. });
  61. </script>