eunja511005 / AutoCoding

0 stars 0 forks source link

공통 코드 셀렉트 박스 공통 기능 구현 #20

Open eunja511005 opened 1 year ago

eunja511005 commented 1 year ago

화면 로딩시 셀렉트 박스 CommonCode 테이블에서 공통으로 가져 올 수 있도록 구현

<select class="form-select" id="modalVisibility" name="openTarget" required></select>
<select class="form-select" id="modalPostType" name="postType" required></select>
    populateSelectBox('modalVisibility', '/commonCode/VISIBILITY');
    populateSelectBox('modalPostType', '/commonCode/POSTTYPE');
function populateSelectBox(selectBoxId, url) {
      var selectBox = $('#' + selectBoxId);
      selectBox.empty();
      selectBox.append($('<option>').val('').text('ALL'));
      $.ajax({
        url: url,
        success: function(response) {
              if (response.success) {

                  $.each(response.data, function(index, commonCode) {
                      selectBox.append($('<option>').val(commonCode.code).text(commonCode.value));
                  });
              } else {
                    swal({
                          title: "Application Error",
                          text: response.errorMessage,
                          icon: "warning",
                          button: "OK",
                    })
              }
         },
         error: function() {
                swal({
                      title: "Ajax Error",
                      text: "Failed to get the common code data.",
                      icon: "warning",
                      button: "OK",
                })
         },
      });
    }