form.blade.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. $contentData = false;
  3. if($section){
  4. $contentData = json_decode($section->content_data, true);
  5. }
  6. if(!$contentData) {
  7. $contentData = [];
  8. }
  9. $formID = rand(0, 100000);
  10. ?>
  11. <form method="POST" action="/process_form_submit" onsubmit="return submitForm_NoteSection_{{ $formID }}(this);">
  12. <?php if($section): ?>
  13. <input type="hidden" name="section_uid" value="<?= $section->uid?>">
  14. <?php else: ?>
  15. <input type="hidden" name="note_uid" value="<?= $note->uid?>">
  16. <input type="hidden" name="section_template_uid" value="<?= $sectionTemplate->uid ?>">
  17. <?php endif; ?>
  18. <!-- __GENERATED_MARKUP__ -->
  19. <div class="form-group m-0 d-flex">
  20. <button class="btn btn-sm btn-primary mr-2">Done</button>
  21. {{--<button class="btn btn-sm btn-default border" onclick="return cancelForm_NoteSection_{{ $formID }}(this)">Cancel</button>--}}
  22. </div>
  23. </form>
  24. <script>
  25. function submitForm_NoteSection_{{ $formID }}(_form) {
  26. showMask();
  27. $.post(_form.action, $(_form).serialize(), function(_data) {
  28. fastReload();
  29. });
  30. return false;
  31. }
  32. function cancelForm_NoteSection_{{ $formID }}(_trigger) {
  33. $(_trigger).closest('.note-section').toggleClass('edit');
  34. return false;
  35. }
  36. function onGemVChange_{{ $formID }}(_field) {
  37. let name = _field.name, span = $('span[field="' + _field.name + '"]');
  38. if(span.length) {
  39. span.text(_field.value);
  40. }
  41. else {
  42. name = _field.name.replace('[]', '');
  43. span = $('span[field="' + name + '"]');
  44. if(span.length) {
  45. let value = [];
  46. $('[name="' + _field.name + '"]').each(function() {
  47. if(this.checked) value.push(this.value);
  48. });
  49. span.text(value.join(', '));
  50. }
  51. }
  52. // submit here
  53. let form = $(_field).closest('form');
  54. $.post(form[0].action, form.serialize(), function(_data) {
  55. console.log('Submitted!');
  56. });
  57. }
  58. </script>