Error: Thymeleaf is disabling the responsiveness of my Bootstrap form. How to resolve?

Asked

Viewed 127 times

1

I’m creating a small web application to learn more about Spring Boot. I’m using the Thymeleaf as engine HTML and the Bootstrap as framework front-end. The problem is that I don’t know why, and I don’t know how to fix it, it’s disabling the responsiveness of my form. It should be the width of the container, but

He’s like this:

inserir a descrição da imagem aqui

Observing: I’m using CDN Bootstrap instead of local files.

Can anyone help me? Already a lot, thank you!

Follow the codes:

Observing: Complete project on Github.

Filing cabinet layout.html:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" th:href="@{css/custom.css}">
        <link rel="stylesheet" th:href="@{https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css}" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
        <title>Amigos leitores</title>
    </head>
        <body>
        <header>
            <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
              <a class="navbar-brand" th:href="@{/}">
                <img th:src="@{/img/TheLibraryFriends.png}" src="../static/img/TheLibraryFriends.png" />
              </a>
              <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
              </button>
              <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                  <li class="nav-item active">
                    <a class="nav-link" th:href="@{/}">Home <span class="sr-only">(current)</span></a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" th:href="@{sobrenos}">Sobre nós</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" th:href="@{regras}">Regras</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link disabled" th:href="@{novoContato}">Entre em Contato!</a>
                  </li>
                </ul>
              </div>
            </nav>  
        </header>
        <br />

        <div class="container">
            <br />
            <h1 layout:fragment="header">Cabeçalho falso</h1>
            <div layout:fragment="content">Conteúdo falso</div>
        </div>
        <script th:src="@{https://code.jquery.com/jquery-3.3.1.slim.min.js}" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script th:src="@{https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js}" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
        <script th:src="@{https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js}" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    </body>
</html>

Filing cabinet formContato.html:

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{Layout}">
    <head>
        <meta charset="UTF-8" />
    </head>
    <body>
    <h1 layout:fragment="header">Fale conosco!</h1>
    <div layout:fragment="content">Dúvidas, críticas e sugestões. Esse é o lugar!
    <br />
    <br />
    <form id="contato" th:action="@{/(formContato)}" th:object="${contato}" action="#" method="post">
        <div th:if="${#fields.hasErrors('*')}" class="alert alert-error">
            <p th:each="error : ${#fields.errors('*')}" th:text="${error}">Erro de validação</p>
        </div>
        <input type="hidden" th:field="*{id}" th:class="${#fields.hasErrors('id')} ? 'field-error'" />
      <div class="form-group">
        <label for="nome">Nome:*</label>
        <input type="text" class="form-control" id="nome" placeholder="Digite seu nome..." th:field="*{nome}" th:class="${#fields.hasErrors('nome')} ? 'field-error'" />
      </div>
      <div class="form-group">
        <label for="email">E-mail:*</label>
        <input type="text" class="form-control" id="email" placeholder="Digite seu e-mail..."  th:field="*{email}" th:class="${#fields.hasErrors('email')} ? 'field-error'" />
      </div>
      <div class="form-group">
        <label for="assunto">Assunto:*</label>
        <input type="text" class="form-control" id="assunto" placeholder="Dê um breve título a sua mensagem..." th:field="*{assunto}" th:class="${#fields.hasErrors('assunto')} ? 'field-error'" />
      </div>
      <div class="form-group">
            <label for="mensagem">Mensagem:*</label>
            <textarea class="form-control" id="mensagem" rows="3" placeholder="Mensagem..." th:field="*{mensagem}" th:class="${#fields.hasErrors('mensagem')} ? 'field-error'" >
            </textarea>
      </div>
      <div class="form-group float-right">
            <a th:href="@{/}" href="index.html"><input type="button" class="btn btn-dark" value="Voltar" /></a>
            <input type="reset" class="btn btn-dark" value="Limpar" />
            <input type="submit" class="btn btn-dark" value="Enviar" />
      </div>
    </form>
    </div>

    </body>
</html>

Filing cabinet custom.css:

body{
    background-color: #fafafa !important;
}

1 answer

0


Guys, the problem was solved in another forum where I asked the same question. But I’ll leave it here, in case someone is having the same difficulty.

Like I was wearing th:class he was "overwriting" the class="form-control" of tag <form>. This was resolved, as suggested to me in this answer here, there in the GUJ, replacing th:class for th:classappend.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.