Disable input in the form

Asked

Viewed 30 times

0

I intend to disable form inputs. I know that the disabled or the readonly does this process. I intend to use the readonly on the form.

I’ll post the code and then explain the problem:

@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>

The problem is in css and I can’t find it. The problem is that when I put readonly="true" in the input, the value of that input is only visible if you click on the input and want it to always be visible

1 answer

1


Use the attribute itself readonly as selector and put in it the same class that in the state :focus, guy [readonly="true"] + .control-label { } also, put a color in the input that you have readonly for the text appears

  @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>

Browser other questions tagged

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