group.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <title>表单组合</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>表单</cite></a>
  7. <a><cite>表单组合</cite></a>
  8. </div>
  9. </div>
  10. <div class="layui-fluid">
  11. <div class="layui-card">
  12. <div class="layui-card-header">表单组合</div>
  13. <div class="layui-card-body" style="padding: 15px;">
  14. <form class="layui-form" action="" lay-filter="component-form-group">
  15. <div class="layui-form-item">
  16. <label class="layui-form-label">单行输入框</label>
  17. <div class="layui-input-block">
  18. <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
  19. </div>
  20. </div>
  21. <div class="layui-form-item">
  22. <label class="layui-form-label">验证必填项</label>
  23. <div class="layui-input-block">
  24. <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
  25. </div>
  26. </div>
  27. <div class="layui-form-item">
  28. <div class="layui-inline">
  29. <label class="layui-form-label">验证手机</label>
  30. <div class="layui-input-inline">
  31. <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
  32. </div>
  33. </div>
  34. <div class="layui-inline">
  35. <label class="layui-form-label">验证邮箱</label>
  36. <div class="layui-input-inline">
  37. <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input">
  38. </div>
  39. </div>
  40. </div>
  41. <div class="layui-form-item">
  42. <div class="layui-inline">
  43. <label class="layui-form-label">多规则验证</label>
  44. <div class="layui-input-inline">
  45. <input type="text" name="number" lay-verify="required|number" autocomplete="off" class="layui-input">
  46. </div>
  47. </div>
  48. <div class="layui-inline">
  49. <label class="layui-form-label">验证日期</label>
  50. <div class="layui-input-inline">
  51. <input type="text" name="date" id="LAY-component-form-group-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
  52. </div>
  53. </div>
  54. <div class="layui-inline">
  55. <label class="layui-form-label">验证链接</label>
  56. <div class="layui-input-inline">
  57. <input type="tel" name="url" lay-verify="url" autocomplete="off" class="layui-input">
  58. </div>
  59. </div>
  60. </div>
  61. <div class="layui-form-item">
  62. <label class="layui-form-label">验证身份证</label>
  63. <div class="layui-input-block">
  64. <input type="text" name="identity" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
  65. </div>
  66. </div>
  67. <div class="layui-form-item">
  68. <label class="layui-form-label">自定义验证</label>
  69. <div class="layui-input-inline">
  70. <input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
  71. </div>
  72. <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
  73. </div>
  74. <div class="layui-form-item">
  75. <div class="layui-inline">
  76. <label class="layui-form-label">范围</label>
  77. <div class="layui-input-inline" style="width: 100px;">
  78. <input type="text" name="price_min" placeholder="¥" autocomplete="off" class="layui-input">
  79. </div>
  80. <div class="layui-form-mid">-</div>
  81. <div class="layui-input-inline" style="width: 100px;">
  82. <input type="text" name="price_max" placeholder="¥" autocomplete="off" class="layui-input">
  83. </div>
  84. </div>
  85. </div>
  86. <div class="layui-form-item">
  87. <label class="layui-form-label">单行选择框</label>
  88. <div class="layui-input-block">
  89. <select name="interest" lay-filter="aihao">
  90. <option value=""></option>
  91. <option value="0">写作</option>
  92. <option value="1" selected="">阅读</option>
  93. <option value="2">游戏</option>
  94. <option value="3">音乐</option>
  95. <option value="4">旅行</option>
  96. </select>
  97. </div>
  98. </div>
  99. <div class="layui-form-item">
  100. <div class="layui-inline">
  101. <label class="layui-form-label">分组选择框</label>
  102. <div class="layui-input-inline">
  103. <select name="quiz">
  104. <option value="">请选择问题</option>
  105. <optgroup label="城市记忆">
  106. <option value="你工作的第一个城市">你工作的第一个城市</option>
  107. </optgroup>
  108. <optgroup label="学生时代">
  109. <option value="你的工号">你的工号</option>
  110. <option value="你最喜欢的老师">你最喜欢的老师</option>
  111. </optgroup>
  112. </select>
  113. </div>
  114. </div>
  115. <div class="layui-inline">
  116. <label class="layui-form-label">搜索选择框</label>
  117. <div class="layui-input-inline">
  118. <select name="modules" lay-verify="required" lay-search="">
  119. <option value="">直接选择或搜索选择</option>
  120. <option value="1">layer</option>
  121. <option value="2">form</option>
  122. <option value="3">layim</option>
  123. <option value="4">element</option>
  124. <option value="5">laytpl</option>
  125. <option value="6">upload</option>
  126. <option value="7">laydate</option>
  127. <option value="8">laypage</option>
  128. <option value="9">flow</option>
  129. <option value="10">util</option>
  130. <option value="11">code</option>
  131. <option value="12">tree</option>
  132. <option value="13">layedit</option>
  133. <option value="14">nav</option>
  134. <option value="15">tab</option>
  135. <option value="16">table</option>
  136. <option value="17">select</option>
  137. <option value="18">checkbox</option>
  138. <option value="19">switch</option>
  139. <option value="20">radio</option>
  140. </select>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="layui-form-item">
  145. <label class="layui-form-label">联动选择框</label>
  146. <div class="layui-input-block">
  147. <div class="layui-inline">
  148. <select name="quiz1">
  149. <option value="">请选择省</option>
  150. <option value="浙江" selected="">浙江省</option>
  151. <option value="你的工号">江西省</option>
  152. <option value="你最喜欢的老师">福建省</option>
  153. </select>
  154. </div>
  155. <div class="layui-inline">
  156. <select name="quiz2">
  157. <option value="">请选择市</option>
  158. <option value="杭州">杭州</option>
  159. <option value="宁波" disabled="">宁波</option>
  160. <option value="温州">温州</option>
  161. <option value="温州">台州</option>
  162. <option value="温州">绍兴</option>
  163. </select>
  164. </div>
  165. <div class="layui-inline">
  166. <select name="quiz3">
  167. <option value="">请选择县/区</option>
  168. <option value="西湖区">西湖区</option>
  169. <option value="余杭区">余杭区</option>
  170. <option value="拱墅区">临安市</option>
  171. </select>
  172. </div>
  173. <div class="layui-inline">
  174. <div class="layui-form-mid layui-word-aux">此处只是演示联动排版,并未做联动交互</div>
  175. </div>
  176. </div>
  177. </div>
  178. <div class="layui-form-item">
  179. <label class="layui-form-label">复选框</label>
  180. <div class="layui-input-block">
  181. <input type="checkbox" name="like[write]" title="写作">
  182. <input type="checkbox" name="like[read]" title="阅读" checked="">
  183. <input type="checkbox" name="like[game]" title="游戏">
  184. </div>
  185. </div>
  186. <div class="layui-form-item" pane="">
  187. <label class="layui-form-label">原始复选框</label>
  188. <div class="layui-input-block">
  189. <input type="checkbox" name="like1[write]" lay-skin="primary" title="写作" checked="">
  190. <input type="checkbox" name="like1[read]" lay-skin="primary" title="阅读">
  191. <input type="checkbox" name="like1[game]" lay-skin="primary" title="游戏" disabled="">
  192. </div>
  193. </div>
  194. <div class="layui-form-item">
  195. <label class="layui-form-label">开关-默认关</label>
  196. <div class="layui-input-block">
  197. <input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF">
  198. </div>
  199. </div>
  200. <div class="layui-form-item">
  201. <label class="layui-form-label">开关-默认开</label>
  202. <div class="layui-input-block">
  203. <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="component-form-switchTest" lay-text="ON|OFF">
  204. </div>
  205. </div>
  206. <div class="layui-form-item">
  207. <label class="layui-form-label">单选框</label>
  208. <div class="layui-input-block">
  209. <input type="radio" name="sex" value="男" title="男" checked="">
  210. <input type="radio" name="sex" value="女" title="女">
  211. <input type="radio" name="sex" value="禁" title="禁用" disabled="">
  212. </div>
  213. </div>
  214. <div class="layui-form-item layui-form-text">
  215. <label class="layui-form-label">普通文本域</label>
  216. <div class="layui-input-block">
  217. <textarea name="text" placeholder="请输入内容" class="layui-textarea"></textarea>
  218. </div>
  219. </div>
  220. <div class="layui-form-item">
  221. <div class="layui-input-block">
  222. <div class="layui-footer">
  223. <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
  224. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  225. </div>
  226. </div>
  227. </div>
  228. </form>
  229. </div>
  230. </div>
  231. </div>
  232. <script>
  233. layui.use(['admin', 'form', 'laydate'], function(){
  234. var $ = layui.$
  235. ,admin = layui.admin
  236. ,element = layui.element
  237. ,layer = layui.layer
  238. ,laydate = layui.laydate
  239. ,form = layui.form;
  240. form.render(null, 'component-form-group');
  241. laydate.render({
  242. elem: '#LAY-component-form-group-date'
  243. });
  244. /* 自定义验证规则 */
  245. form.verify({
  246. title: function(value){
  247. if(value.length < 5){
  248. return '标题至少得5个字符啊';
  249. }
  250. }
  251. ,pass: [/(.+){6,12}$/, '密码必须6到12位']
  252. ,content: function(value){
  253. layedit.sync(editIndex);
  254. }
  255. });
  256. /* 监听指定开关 */
  257. form.on('switch(component-form-switchTest)', function(data){
  258. layer.msg('开关checked:'+ (this.checked ? 'true' : 'false'), {
  259. offset: '6px'
  260. });
  261. layer.tips('温馨提示:请注意开关状态的文字可以随意定义,而不仅仅是ON|OFF', data.othis)
  262. });
  263. /* 监听提交 */
  264. form.on('submit(component-form-demo1)', function(data){
  265. layer.alert(JSON.stringify(data.field), {
  266. title: '最终的提交信息'
  267. })
  268. return false;
  269. });
  270. });
  271. </script>