0

Pretendo desativar os inputs do formulário. Sei que o disabled ou o readonly faz esse processo. Pretendo usar o readonly no formulário.

Vou postar o código e depois explico o problema:

@import url(https://fonts.googleapis.com/css?family=Roboto);
body,
input,
select,
textarea,
body * {
  font-family: 'Roboto', sans-serif;
  box-sizing: border-box;
}
body::after, body::before,
input::after,
input::before,
select::after,
select::before,
textarea::after,
textarea::before,
body *::after,
body *::before {
  box-sizing: border-box;
}

.form-radio,
.form-group {
  position: relative;

}

.form-inline > .form-group,
.form-inline > .btn {
  display: inline-block;
  margin-bottom: 0;
}

.form-group input {
  height: 1.9rem;
}

.form-group .control-label {
  position: absolute;
  top: 0.25rem;
  pointer-events: none;
  padding-left: 0.125rem;
  z-index: 1;
  color: #3a3a3a;
  font-size: 1rem;
  font-weight: normal;
  -webkit-transition: all 0.28s ease;
  transition: all 0.28s ease;
}

.form-group .bar {
  position: relative;
  border-bottom: 0.0625rem solid #999;
  display: block;
}
.form-group .bar::before {
  content: '';
  height: 0.125rem;
  width: 0;
  left: 50%;
  bottom: -0.0625rem;
  position: absolute;
  background: #337ab7;
  -webkit-transition: left 0.28s ease, width 0.28s ease;
  transition: left 0.28s ease, width 0.28s ease;
  z-index: 2;
}
.form-group input,
.form-group textarea {
  display: block;
  background: none;
  padding: 0.125rem 0.125rem 0.0625rem;
  font-size: 1rem;
  border-width: 0;
  border-color: transparent;
  line-height: 1.9;
  width: 100%;
  color: transparent;
  -webkit-transition: all 0.28s ease;
  transition: all 0.28s ease;
  box-shadow: none;
}

.form-group select,
.form-group input:focus,
.form-group input:valid,
.form-group input.form-file,
.form-group input.has-value,
.form-group textarea:focus,
.form-group textarea:valid,
.form-group textarea.form-file,
.form-group textarea.has-value {
  color: #333;
}
.form-group select ~ .control-label,
.form-group input:focus ~ .control-label,
.form-group input:valid ~ .control-label,
.form-group input.form-file ~ .control-label,
.form-group input.has-value ~ .control-label,
.form-group textarea:focus ~ .control-label,
.form-group textarea:valid ~ .control-label,
.form-group textarea.form-file ~ .control-label,
.form-group textarea.has-value ~ .control-label {
  font-size: 0.8rem;
  color: #3a3a3a;
  top: -1rem;
  left: 0;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
}
.form-group select:focus ~ .control-label,
.form-group input:focus ~ .control-label,
.form-group textarea:focus ~ .control-label {
  color: #337ab7;
}
.form-group select:focus ~ .bar::before,
.form-group input:focus ~ .bar::before,
.form-group textarea:focus ~ .bar::before {
  width: 100%;
  left: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form class="text-center border border-light largura limp6" action="#!">

     <div class="h4 mb-4">CONSULTAR PEDIDO DE MANUTENÇÃO</div>
                       <div style="clear:both;"></div>
                        <div class="row">
                        <div class="col-md-4 col-xs-4">
                            <div class="form-group">
                                <input type="text" id="Pedi" name="Pedi" value="teste" readonly="true">
                                <label for="Pedi" class="control-label">Pedido</label><i class="bar"></i>
                            </div>
                        </div>
          </div>
</form>

O problema está no css e não consigo encontrar. O problema é que quando coloco readonly="true" no input, o valor desse input só fica visível se clicar no input e pretendo que fique sempre visível

1 Resposta 1

1

Use o próprio atributo readonly como seletor e coloque nele a mesma class que no estado :focus, tipo [readonly="true"] + .control-label { } além disso, coloque um color no input que tiver readonly para o texto aparece

  @import url(https://fonts.googleapis.com/css?family=Roboto);

  body,
  input,
  select,
  textarea,
  body * {
    font-family: 'Roboto', sans-serif;
    box-sizing: border-box;
  }

  body::after,
  body::before,
  input::after,
  input::before,
  select::after,
  select::before,
  textarea::after,
  textarea::before,
  body *::after,
  body *::before {
    box-sizing: border-box;
  }

  .form-radio,
  .form-group {
    position: relative;

  }

  .form-inline > .form-group,
  .form-inline > .btn {
    display: inline-block;
    margin-bottom: 0;
  }

  .form-group input {
    height: 1.9rem;
  }

  .form-group .control-label {
    position: absolute;
    top: 0.25rem;
    pointer-events: none;
    padding-left: 0.125rem;
    z-index: 1;
    color: #3a3a3a;
    font-size: 1rem;
    font-weight: normal;
    -webkit-transition: all 0.28s ease;
    transition: all 0.28s ease;
  }

  .form-group .bar {
    position: relative;
    border-bottom: 0.0625rem solid #999;
    display: block;
  }

  .form-group .bar::before {
    content: '';
    height: 0.125rem;
    width: 0;
    left: 50%;
    bottom: -0.0625rem;
    position: absolute;
    background: #337ab7;
    -webkit-transition: left 0.28s ease, width 0.28s ease;
    transition: left 0.28s ease, width 0.28s ease;
    z-index: 2;
  }

  .form-group input,
  .form-group textarea {
    display: block;
    background: none;
    padding: 0.125rem 0.125rem 0.0625rem;
    font-size: 1rem;
    border-width: 0;
    border-color: transparent;
    line-height: 1.9;
    width: 100%;
    color: transparent;
    -webkit-transition: all 0.28s ease;
    transition: all 0.28s ease;
    box-shadow: none;
  }

  .form-group select,
  .form-group input:focus,
  .form-group input:valid,
  .form-group input.form-file,
  .form-group input.has-value,
  .form-group textarea:focus,
  .form-group textarea:valid,
  .form-group textarea.form-file,
  .form-group textarea.has-value {
    color: #333;
  }

  .form-group select ~ .control-label,
  .form-group input:focus ~ .control-label,
  .form-group input:valid ~ .control-label,
  .form-group input.form-file ~ .control-label,
  .form-group input.has-value ~ .control-label,
  .form-group textarea:focus ~ .control-label,
  .form-group textarea:valid ~ .control-label,
  .form-group textarea.form-file ~ .control-label,
  .form-group textarea.has-value ~ .control-label {
    font-size: 0.8rem;
    color: #3a3a3a;
    top: -1rem;
    left: 0;
  }

  .form-group select:focus,
  .form-group input:focus,
  .form-group textarea:focus {
    outline: none;
  }

  .form-group select:focus ~ .control-label,
  .form-group input:focus ~ .control-label,
  .form-group textarea:focus ~ .control-label {
    color: #337ab7;
  }

  .form-group select:focus ~ .bar::before,
  .form-group input:focus ~ .bar::before,
  .form-group textarea:focus ~ .bar::before {
    width: 100%;
    left: 0;
  }

  [readonly="true"] {
    color: #333333 !important;
  }

  [readonly="true"] + .control-label {
    font-size: 0.8rem !important;
    color: #3a3a3a !important;
    top: -1rem !important;
    left: 0 !important;
  }
  <form class="text-center border border-light largura limp6" action="#!">

    <div class="h4 mb-4">CONSULTAR PEDIDO DE MANUTENÇÃO</div>
    <div style="clear:both;"></div>
    <div class="row">
      <div class="col-md-4 col-xs-4">
        <div class="form-group">
          <input type="text" id="Pedi" name="Pedi" value="teste" readonly="true">
          <label for="Pedi" class="control-label">Pedido</label><i class="bar"></i>
        </div>
      </div>
    </div>
  </form>

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .