• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

12:15와는 다른 화면이 나옵니다.

23.09.08 22:11 작성 조회수 218

0

읽기 쉽게 fragments.html에 있는 코드를 settings.tags.html에 옮겨 적었습니다.

코드 내용

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Study Club</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@yaireo/tagify@3.5.1/dist/tagify.css">

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/jdenticon@3.2.0/dist/jdenticon.min.js" async
            integrity="sha384-yBhgDqxM50qJV5JPdayci8wCfooqvhFYbIKhv0hTtLvfeeyJMJCscRfFNKIxt43M" crossorigin="anonymous">
    </script>
    <style>
        .container{
            max-width: 100%;
        }
        .tagify-outside{
            border: 0;
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body class="bg-light">
    <nav class="navbar navbar-expand-sm navbar-dark bg-dark">
        <a class="navbar-brand" href="/" th:href="@{/}">
            <img src="/images/logo_symbol.png" width="30" height="30">
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
    
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item">
                    <form th:action="@{/search/study}" class="form-inline" method="get">
                        <input class="form-control mr-sm-2" name="keyword" type="search" placeholder="스터디 찾기" aria-label="Search" />
                    </form>
                </li>
            </ul>
    
            <ul class="navbar-nav justify-content-end">
                <li class="nav-item" sec:authorize="!isAuthenticated()">
                    <a class="nav-link" th:href="@{/login}">로그인</a>
                </li>
                <li class="nav-item" sec:authorize="!isAuthenticated()">
                    <a class="nav-link" th:href="@{/sign-up}">가입</a>
                </li>
                <li class="nav-item" sec:authorize="isAuthenticated()">
                    <a class="nav-link" th:href="@{/notifications}">
                        <i class="fa fa-bell-o"></i>
                    </a>
                </li>
                <li class="nav-item" sec:authorize="isAuthenticated()">
                    <a class="nav-link btn btn-outline-primary" th:href="@{/notifications}">
                        <i class="fa fa-plus" aria-hidden="true"></i> 스터디 개설
                    </a>
                </li>
                <li class="nav-item dropdown" sec:authorize="isAuthenticated()">
                    <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        <svg th:if="${#strings.isEmpty(account?.profileImage)}" data-jdenticon-value="user127" th:data-jdenticon-value="${#authentication.name}"
                             width="24" height="24" class="rounded border bg-light"></svg>
                        <img th:if="${!#strings.isEmpty(account?.profileImage)}" th:src="${account.profileImage}"
                             width="24" height="24" class="rounded border"/>
                    </a>
                    <div class="dropdown-menu dropdown-menu-sm-right" aria-labelledby="userDropdown">
                        <h6 class="dropdown-header">
                            <span sec:authentication="name">Username</span>
                        </h6>
                        <a class="dropdown-item" th:href="@{'/profile/' + ${#authentication.name}}">프로필</a>
                        <a class="dropdown-item" >스터디</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#" th:href="@{'/settings/profile'}">설정</a>
                        <form class="form-inline my-2 my-lg-0" action="#" th:action="@{/logout}" method="post">
                            <button class="dropdown-item" type="submit">로그아웃</button>
                        </form>
                    </div>
                </li>
            </ul>
        </div>
    </nav>
<div class="container">
  <div class="row mt-5 justify-content-center">
    <div class="col-2">
        <div class="list-group">
            <a class="list-group-item list-group-item-action" th:classappend="${currentMenu == 'profile'}? active" href="#" th:href="@{/settings/profile}">프로필</a>
            <a class="list-group-item list-group-item-action" th:classappend="${currentMenu == 'password'}? active" href="#" th:href="@{/settings/password}">비밀번호</a>
            <a class="list-group-item list-group-item-action" th:classappend="${currentMenu == 'notifications'}? active" href="#" th:href="@{/settings/notifications}">알림</a>
            <a class="list-group-item list-group-item-action" th:classappend="${currentMenu == 'tags'}? active" href="#" th:href="@{/settings/tags}">관심 주제</a>
            <a class="list-group-item list-group-item-action" th:classappend="${currentMenu == 'zones'}? active" href="#" th:href="@{/settings/zones}">활동 지역</a>
            <a class="list-group-item list-group-item-action list-group-item-danger" th:classappend="${currentMenu == 'account'}? active" href="#" th:href="@{/settings/account}">계정</a>
        </div>
    </div>
    <div class="col-8">
      <div class="row">
        <h2 class="col-12">관심있는 스터디 주제</h2>
      </div>
      <div class="row">
        <div class="col-12">
          <div class="alert alert-info" role="alert">
            참여하고 싶은 스터디 주제를 입력해 주세요. 스터디가 생기면 알림을 받을 수 있습니다. 태그 입력 후 콤마(,) 또는 엔터를 입력하세요.
          </div>
          <input id="tags" type="text" name="tags" class="tagify-outside" aria-describedby="tagHelp"/>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="application/javascript" th:inline="javascript">
    $(function () {
        var csrfToken = /*[[${_csrf.token}]]*/ null;
        var csrfHeader = /*[[${_csrf.headerName}]]*/ null;
        $(document).ajaxSend(function (e, xhr, options){
            xhr.setRequestHeader(csrfHeader, csrfToken);
        });
    });
</script>
<script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify@3.5.1/dist/tagify.min.js"></script>
    <script type="application/javascript" th:inline="javascript">
        $(function() {
            function tagRequest(url, tagTitle) {
                $.ajax({
                    dataType: "json",
                    autocomplete: {
                        enabled: true,
                        rightKey: true,
                    },
                    contentType: "application/json; charset=utf-8",
                    method: "POST",
                    url: "[(${baseUrl})]" + url,
                    data: JSON.stringify({'tagTitle': tagTitle})
                }).done(function (data, status) {
                    console.log("${data} and status is ${status}");
                });
            }

            function onAdd(e) {
                tagRequest("/add", e.detail.data.value);
            }

            function onRemove(e) {
                tagRequest("/remove", e.detail.data.value);
            }

            var tagInput = document.querySelector("#tags");
            var tagify = new Tagify(tagInput, {
                pattern: /^.{0,20}$/,
                whitelist: JSON.parse(document.querySelector("#whitelist").textContent),
                dropdown : {
                    enabled: 1, // suggest tags after a single character input
                } // map tags
            });
            tagify.on("add", onAdd);
            tagify.on("remove", onRemove);

            // add a class to Tagify's input element
            tagify.DOM.input.classList.add('form-control');
            // re-place Tagify's input element outside of the  element (tagify.DOM.scope), just before it
            tagify.DOM.scope.parentNode.insertBefore(tagify.DOM.input, tagify.DOM.scope);
        });
    </script>
</body>
</html>

결과 화면

스크린샷 2023-09-08 오후 9.33.07.png

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.09.10

안녕하세요, 인프런 AI 인턴이에요.

코드를 옮겨 적으셨다고 하셨는데, 지금은 다른 화면이 나오고 있는 것으로 이해하겠습니다. 현재 코드에서 어떤 문제가 발생하고 있는지 자세히 설명해주시면 도움을 드릴 수 있을 것 같아요.

화면이 나오지 않는 부분의 코드와 함께 에러 메시지나 원하는 기능에 대한 설명을 상세하게 적어주시면 빠르게 답변해드리겠습니다.

image

구글 개발자 모드에서 이렇게 경고가 나옵니다.

수업에서 보여준 코드대로 작성하니 뷰가 정상적으로 떴습니다.