Topic: MDB Bootstrap Support
Hi,
After hours of brainstorming, i don't find a way to fix this issue.
I managed to get a working code of the radio button outside the mdbModal.
Inside the mdbModal, the Radio button have problems to show the correct state. If i click on the checked one, the check disappear, if i click on a blank one, nothing happen. (i have edited the previous code to make it simple)
<div mdbModal #itemDocumentBuilderProductEditionModal="mdb-modal" class="modal fade" id="crudformModalId" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" [config]="{ignoreBackdropClick: true}" aria-hidden="true">
<div class="modal-dialog modal-fluid" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="editModalCancel()">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title w-100 dark-grey-text font-weight-bold my-3" id="myModalLabel">
<div><span>Document generator</span></div>
</h4>
</div>
<div class="form-inline">
<div id="mainForm" class="tab-content card">
<div class="form-check">
<input type="radio" class="form-check-input" id="radioGap1" name="groupOfRadioGap" checked>
<label class="form-check-label" for="radioGap1">Option 1</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radioGap2" name="groupOfRadioGap">
<label class="form-check-label" for="radioGap2">Option 2</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" id="radioGap3" name="groupOfRadioGap">
<label class="form-check-label" for="radioGap3">Option 3</label>
</div>
<!-- Don t put this in Form balise or it s a mess to position the button -->
</div>
</div>
</div>
</div>
</div>
Damian Gemza staff answered 6 years ago
Dear @ITSaltel
Unfortunately, I'm unable to reproduce your problem with the latest version of MDB Angular.
I have copied your code to my application and opened the modal.
When I was clicking on the checked one, nothing happens (that's the right behavior).
When I clicked on one of the blank ones, the radio button was selected (again, correct behavior).
Could you please check, if your browser console throws some errors? Maybe try to execute npm install one more time?
Also update your project to the latest MDB Angular version, and check, if this problem still exists.
Best Regards,
Damian
ITSaltel pro answered 6 years ago
Hi,
I finally understand what happens.
The radio button is include in a component. The component is called twice by a parent component. If i remove one or the other, it works. It s related to the Id of the radio button. It have to be unique.
Below are the the two way.
component parent => child 1 => child 2 => child 3=>child with radio button
or
component parent => child with radio button.
So how can i call a component twice time while having different ID for the radio Buttton. I will have to sort this out. Other way is to clone the child with radio button but this is not good for refactoring.
ITSaltel pro answered 6 years ago
A workaround solution was to add a condition who show the component only if we are about to use it. This way, we only have one instance of the component.
<div *ngIf="crudFormHelper">
<child-with-radio-button></child-with-radio-button>
</div>
Damian Gemza staff answered 6 years ago
Dear @ITSaltel
I'm marking this ticket as resolved because you have found the answer on your own.
Best Regards,
Damian
ITSaltel pro answered 6 years ago
Hi,
Using <div *ngIf="crudFormHelper"> wasn't a good idea at the end. I had to face to an other problem.
The best solution is to generate a unique Id for the radio button like that. Tested and aproved.
<formclass="form-inline">
<!--Removed <form> to avoid error on "Enter" key for search -->
<divid="mainForm"class="tab-content card">
<divclass="form-group row">
<divclass="col-2"></div>
</div>
<divclass="form-check">
<inputtype="radio"class="form-check-input"[id]="'materialUnchecked'+uId"[name]="'materialExampleRadios'+uId"
mdbInputDirective>
<labelclass="form-check-label"[for]="'materialUnchecked'+uId">Material unchecked</label>
</div>
<!-- Material checked -->
<divclass="form-check">
<inputtype="radio"class="form-check-input"[id]="'materialChecked'+uId"[name]="'materialExampleRadios'+uId"
checkedmdbInputDirective>
<labelclass="form-check-label"[for]="'materialChecked'+uId">Material checked</label>
</div>
</div>
</form>
In the TS file :
privateuId:string='_'+Math.random().toString(36).substr(2, 9);
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 5.2.3
- Device: PC
- Browser: Chrome
- OS: Windows 10
- Provided sample code: Yes
- Provided link: No