1
How do I create a condition in a form using Bootstrap 4 ?
I have the following form:
<form id="createusers" class="needs-validation" oninput='userrepassword.setCustomValidity(userrepassword.value != userpassword.value ? "Senhas não conferem." : "")' novalidate>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">
<i class="fa fa-user-circle-o"></i>
</div>
</div>
<input id="username" name="username" placeholder="Usuário" type="text" aria-describedby="usernameHelpBlock" required="required" class="form-control">
<!-- <label for="username">Digite um nome de usuário</label> -->
<div class="invalid-feedback">Por favor, digite um nome de usuário válido.</div>
</div>
<small id="usernameHelpBlock" class="form-text text-muted">Digite um nome de usuário.</small>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">
<i class="fa fa-lock"></i>
</div>
</div>
<input id="userpassword" name="userpassword" placeholder="Senha" type="password" required="required" class="form-control" aria-describedby="userpasswordHelpBlock">
<!-- <label for="userpassword">Digite uma senha para o usuário. Sua senha deve ter no mínimo 6 caracteres.</label> -->
<div class="invalid-feedback">Por favor, digite uma senha.</div>
</div>
<small id="userpasswordHelpBlock" class="form-text text-muted">Digite uma senha para o usuário. Sua senha deve ter no mínimo 6 caracteres.</small>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">
<i class="fa fa-lock"></i>
</div>
</div>
<input id="userrepassword" name="userrepassword" placeholder="Confirme a senha" type="password" required="required" class="form-control" aria-describedby="userrepasswordHelpBlock">
<!-- <label for="userrepassword">Confirme a senha.</label> -->
<div class="invalid-feedback">Por favor, confirme a senha.</div>
</div>
<small id="userrepasswordHelpBlock" class="form-text text-muted">Confirme a senha.</small>
</div>
<div class="form-group">
<label>Informe o grupo do usuário</label>
<div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_0" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="neg">
<label for="usergroup_0" class="custom-control-label">Negado</label>
</div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_1" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="tot">
<label for="usergroup_1" class="custom-control-label">Total</label>
</div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_2" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="controlado">
<label for="usergroup_2" class="custom-control-label">Controlado</label>
</div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_3" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="restrito">
<label for="usergroup_3" class="custom-control-label">Restrito</label>
</div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_4" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="lib">
<label for="usergroup_4" class="custom-control-label">Liberado</label>
</div>
<div class="custom-control custom-radio">
<input name="usergroup" id="usergroup_5" type="radio" aria-describedby="usergroupHelpBlock" required="required" class="custom-control-input" value="noc">
<label for="usergroup_5" class="custom-control-label">No Cache</label>
<div class="invalid-feedback">Por favor, selecione uma opção para informar o grupo do usuário.</div>
</div>
<small id="usergroupHelpBlock" class="form-text text-muted">Informe o grupo do usuário.</small>
</div>
</div>
<div class="form-group">
<button name="submitcreateuser" type="submit" class="btn btn-primary">Criar Usuário</button>
</div>
</form>
I needed another to appear radio
every time you check the "Controlled" option or when you check "Restricted".
Another detail I wanted to know is if you have a password validation and password confirmation using Bootstrap 4 ? As you can see I had to declare oninput on the tag form
to make this validation, but it does not display the message I put "Passwords do not match".
How do I do it ?
Man, about that I had already read everything in the Bootstrap 4 documentation, and this example template that you published, I had already seen everything in the documentation, so much so that I used it as a template to create my forms and you see, it doesn’t have what I need, no password fields and password confirmation, much less conditional.
– Rooh Macedo
I understand, but the forum is to help and guide and not do your job. With the above example you create perfectly what you need. Hug
– user148170
If you were to see the example you passed above you would go through the documentation and not come to ask for help with what I need, since what you replicated above is a CTRL+C and CTRL+V from the Bootstrap 4 documentation itself.
– Rooh Macedo