making a form submission with bootstrap modal question

xuanbao · · 592 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p><strong>EDIT:</strong> I just re-read my post and realized that it sounds like I&#39;m not using go. I am using go 1.10 and gin is what i&#39;m using to route all the traffic and stuff. Sorry about not giving you more context.</p> <p>I&#39;m adding a new feature to a website that will make a new &#34;schedule&#34;. Currently the schedule is a daily thing without consideration for holidays but the feature being added is to start considering holidays in this schedule. I&#39;m bad at front end things like this so what I&#39;ve come up with so far is a bootstrap modal that is opened and controlled with jquery. (FYI I&#39;m not sold on having jquery and bootstrap but it&#39;s existing code and i&#39;m trying to make as small of changes as possible. and slowly introduce big changes and refactoring) So my question is this: what is a fairly typical solution to show a &#34;new ____ form&#34; that posts a model to the API to be saved into a database. The backend stuff is working and last night I was able to get JQuery to get all my values from the inputs and create a object that got posted to the API. (For reference)</p> <pre><code> function submitNewScheduleFromModal() { var record = { &#39;circuitnum&#39;: parseInt($(&#34;#newScheduleForm #circuitNumber&#34;).val()), &#39;ontime&#39;: &#39;Dusk-0&#39;, &#39;offtime&#39;: &#39;Dawn-0&#39;, &#39;sun&#39;: $(&#34;#newScheduleForm #sun&#34;).is(&#34;:checked&#34;), &#39;mon&#39;: $(&#34;#newScheduleForm #mon&#34;).is(&#34;:checked&#34;), &#39;tue&#39;: $(&#34;#newScheduleForm #tue&#34;).is(&#34;:checked&#34;), &#39;wed&#39;: $(&#34;#newScheduleForm #wed&#34;).is(&#34;:checked&#34;), &#39;thu&#39;: $(&#34;#newScheduleForm #thu&#34;).is(&#34;:checked&#34;), &#39;fri&#39;: $(&#34;#newScheduleForm #fri&#34;).is(&#34;:checked&#34;), &#39;sat&#39;: $(&#34;#newScheduleForm #sat&#34;).is(&#34;:checked&#34;), &#39;enabled&#39;: true }; $.ajax({ url: `${globalUrl}/schedule2`, data: JSON.stringify(record), contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, method: &#39;POST&#39; }) .done(function () { window[&#39;grid&#39; + record.circuitnum].reload(); }) .fail(function (jqXHR, textStatus, errorThrown) { console.log(&#39;Failed to add&#39; + textStatus); }); } </code></pre> <p>I&#39;m currently stuck trying to figure out how I can make the ontime and offtime dropdown boxes a little more dynamic and generated in nature instead of the 240 lines of code that append a select tag...( yeah wonderful :/) which got me thinking about do I write my modal in go then serve it up? If so how would I write this modal as a template and ask for a new one each time? Things I just don&#39;t know.</p>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

592 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传