4
Good night.
I am trying to make a login and registration screen for an application that will save the data in localStorage. To prevent the user from registering with incomplete data I disabled the Submit button using disabled.
My intention is when all fields are filled in the property disabled is removed and the button can be clicked but I cannot remove the disabled, tried several ways and nothing. I believe the easiest way would be this:
var operacao = "A"; //"A"=Adição; "E"=Edição
var indice_selecionado = -1; //Índice do item selecionado na lista
var tbUsuarios;
//aqui o botão submit já está desabilitado
$(document).ready(function() {
    $('#buttonSubmitRegister').prop('disabled', true);
});
$(function () {
    tbUsuarios = localStorage.getItem("tbUsuarios");// Recupera os dados armazenados
    tbUsuarios = JSON.parse(tbUsuarios); // Converte string para objeto
    if (tbUsuarios === null) // Caso não haja conteúdo, iniciamos um vetor vazio
        tbUsuarios = [];
});
function Adicionar() {
    var usuario = JSON.stringify({
        Nome: $("#txtNome").val(),
        email: $("#txtEmail").val(),
        Senha: $("#txtSenha").val()
    });
    //aqui tentei remover o disabled quando os campos forem preenchidos
    if ($("#txtNome").val().length > 1 && $("#txtEmail").val().length > 1 && $("#txtSenha").val().length > 1){
        $(document).ready(function() {
            $('#buttonSubmitRegister').prop('disabled', false);
        });
        tbUsuarios.push(usuario);
        localStorage.setItem("tbUsuarios", JSON.stringify(tbUsuarios));
        alert("Usuário Cadastrado com Sucesso!");
        return true;
    }
}<form id="formRegister" nome="formRegister" class="positionFormRegister">
                <div class="input-group">
                    <span class="input-group-addon"></span>
                    <label for="txtNome"></label>
                    <input id="txtNome" name="txtNome" type="text" class="form-control" placeholder="Crie seu nome de Usuário" autocomplete="off">
                </div>
                <div class="input-group">
                    <span class="input-group-addon"></span>
                    <label for="txtEmail"></label>
                    <input id="txtEmail" name="txtEmail" type="text" class="form-control" placeholder="Seu endereço de e-mail" autocomplete="off">
                </div>
                <div class="input-group">
                    <span class="input-group-addon"></span>
                    <label for="txtSenha"></label>
                    <input id="txtSenha" name="txtSenha" type="password" class="form-control" placeholder="Crie sua senha" autocomplete="off">
                </div>
                <!--Botão Submit-->
                <div>
                    <input id="buttonSubmitRegister" type="submit" class="btn btn-primary btn-lg positionFormRegister" value="Cadastrar no e-Pro »" onclick="Adicionar()">
                </div>
            </form>Does anyone have any idea how to fix it? Thanks for the help.
I also tried with ' $("#txtNome"). val(). length != " " '. But it didn’t work
– Mauricio Hartmann