8
I have a page made with bootstrap 3 where I show some fields coming from my BD, now when opening the page I need all fields except a button Iniciar Tarefa
are disabled, the button Iniciar Tarefa
will be responsible for enabling the fields for editing.
I’m trying to use it, but without success:
$(document).READY(function() { // PARA HABILITAR OS CAMPOS DO FORMULÁRIO, MUDAR O true PARA false $("#form :input").prop("disabled", true); // DESABILITA TODOS OS CAMPOS });
This is the form:
<form class="form-horizontal">
<!-- Form Name -->
<legend>Atividade</legend>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="IniciarTarefa"></label>
<div class="col-md-4">
<button id="IniciarTarefa" name="IniciarTarefa" class="btn btn-info">Iniciar Tarefa</button>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="Etapa">Etapa</label>
<div class="col-md-4">
<select id="Etapa" name="Etapa" class="form-control">
<option value="1">Opção 1</option>
<option value="2">Opção 2</option>
</select>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="Ordem">Ordem</label>
<div class="col-md-4">
<input id="Ordem" name="Ordem" type="text" placeholder="Ordem" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="Nome">Nome</label>
<div class="col-md-4">
<input id="Nome" name="Nome" type="text" placeholder="Nome" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="LinkDocumento">Link Documento</label>
<div class="col-md-4">
<input id="LinkDocumento" name="LinkDocumento" type="text" placeholder="Link do Documento" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="DataInicio">Data Início</label>
<div class="col-md-4">
<input id="DataInicio" name="DataInicio" type="text" placeholder="Data Início" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="DataFinal">Data Final</label>
<div class="col-md-4">
<input id="DataFinal" name="DataFinal" type="text" placeholder="Data Final" class="form-control input-md" required="">
</div>
</div>
<!-- Prepended checkbox -->
<div class="form-group">
<label class="col-md-4 control-label" for="Enviar"></label>
<div class="col-md-4">
<div class="input-group"> <span class="input-group-addon">
<input type="checkbox">
</span>
<input id="Enviar" name="Enviar" class="form-control" type="text" placeholder="Enviar E-mail">
</div>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="Descricao">Descrição</label>
<div class="col-md-4">
<textarea class="form-control" id="Descricao" name="Descricao"></textarea>
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="Status">Status</label>
<div class="col-md-4">
<div class="radio">
<label for="Status-0">
<input type="radio" name="Status" id="Status-0" value="1" checked="checked">
Iniciada </label>
</div>
<div class="radio">
<label for="Status-1">
<input type="radio" name="Status" id="Status-1" value="2">
Finalizada </label>
</div>
<div class="radio">
<label for="Status-2">
<input type="radio" name="Status" id="Status-2" value="3">
Cancelada </label>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="FinalizarTarefa"></label>
<div class="col-md-4">
<button id="FinalizarTarefa" name="FinalizarTarefa" class="btn btn-info">Finalizar Tarefa</button>
</div>
</div>
These links may be useful to you: http://stackoverflow.com/questions/1416900/how-to-disable-all-input-insida-form-with-jquery / http://stackoverflow.com/questions/1414365/disable-enable-an-input-with-jquery On one of these links it says the following::
If you only want the <input> elements:

$("#target input").prop("disabled", true);
So remove thedois pontos
and#
(because your form does not have a defined id)#form :input
, being like this:$('form input').prop('disabled', true/false)
;– Rafael Withoeft
Hello @Rafaelwithoeft, thanks for sharing.
– adventistapr
For nothing, it managed to solve the problem?
– Rafael Withoeft
I’m here making the changes.
– adventistapr