Mdb-ui-kit: checkbox issue with Angular 4

Created on 19 Sep 2017  路  22Comments  路  Source: mdbootstrap/mdb-ui-kit

Test Case

I don't have Codepen URL as i am working on big project in angular and having issue related to checkbox in that

Summary

browser/OS : Chrome/Win 7

in my project i have added bootstrap-material-design.min.js and bootstrap-material-design.min.css. Also i have added below line in my app js:
$('body').bootstrapMaterialDesign({ });

All checkboxes and radios are working fine on initial load. Because as it is angular 4 my project will load only once. But after that if i switch to another page and come down to same page again i don't see any checkboxes but can see radios and other controls.

Expected result

checkboxes should be there even after initial load as well.

Additional Information

Here is the code

<div class="checkbox">
                            <label>
                                <input type="checkbox"> Check me out
                            </label>
                        </div>

and in the browser it looks like this

<span class="bmd-form-group is-filled"><div _ngcontent-c4="" class="checkbox">
                                <label _ngcontent-c4="">
                                    <input _ngcontent-c4="" id="checkbox" name="check1" type="checkbox"><span class="bmd-switch-track"></span>
                                </label>
                            </div></span>

Please help.

All 22 comments

@FezVrasta I have already added arrive.js in my project but still its not working. The issue is with Checkboxes only. Radios and switches are working fine for me.
issue #1042 seems like version 3 issue. I am using version 4.

The process is the same. Anyway without a CodePen I can't help you further unfortunately. I would have to manually setup an AngularJS environment, thing I never done before.

@FezVrasta one question: Do i need to include bootstrap js? Currently i have included following js in the same sequence:

jquery.min.js
popper.min.js
arrive.min.js
bootstrap-material-design.min.js

Nope, it's not required

@FezVrasta I still see this issue, even after including arrive.js.
I have two screens - one with checkboxes dynamically added, and another with dynamically added switches.
If I load the screen with switches first, and then load the one with checkboxes, the switches load fine, but the checkboxes only have their labels. If I try it the other way round, both components work fine.
It's really weird and I'm finding it hard to debug.
I don't want to create a separate issue because it would be a duplicate.

Make sure you are including Arrive.js before this project's javascript.

@FezVrasta Yes, I am including arrive.js before bootstrap-material. Specifically in the exact order as mentioned above:
jquery.min.js
popper.min.js
arrive.min.js
bootstrap-material-design.min.js

Sorry without a repro I don't know how to help :-(

If it was a problem with my order of inclusion, none of the components would load properly. But I just mentioned that the switches load fine. Its just the checkboxes.

@FezVrasta steps to reproduce are these:
Use JS to:

  1. Add a few switches dynamically to DOM.
  2. Now add a few checkboxes.
    Checkboxes are not visible, you can only see the labels.
    Switches load fine.
    Now try the reverse.
  3. Add a few checkboxes dynamically to DOM.
  4. Now add a few switches.
    Both will work fine now.

Hope this helps. Thank you for your work. I'm from an A.I. startup in the US and we are trying to get a product out by the end of the month. We really love what you've done and would like to donate to your team after our product is out, as a token of appreciation.

Please provide a codepen, with that I can dedicate some time to look into the problem.

@FezVrasta thank you for responding quickly. I will send you one as soon as I can. Thanks!

I am having a very similar issue. If I view a component that has a switch element and then navigate to a component that has a checkbox, the checkbox does not appear.

I have a plnkr that demonstrates this: https://embed.plnkr.co/tTYGtJ6xj6IDNrMnlREW/

To reproduce: Click on the "Checkbox" button to show a checkbox, then click on the "Switch" button to show a switch, then click on the "Checkbox" button and the checkbox is not visible.

Thanks, does it happens with plain JS?

I haven't seen this issue with plain JS.

Another thing I noticed when inspecting the element is that when the checkbox appears, the HTML is:

<div class="checkbox">
  <label>
    <input type="checkbox">
    <span class="checkbox-decorator"><span class="check"></span>
    <div class="ripple-container"></div></span> Checkbox
  </label>
</div>

However, after I show a switch element and then inspect the checkbox element, the HTML shows up as this:

<div class="checkbox">
  <label>
    <input type="checkbox"><span class="bmd-switch-track"></span> Checkbox
  </label>
</div>

This issue appears for me using Safari, Chrome, and Firefox on OSX.

Hope this helps!

I wonder if it's something Angular is doing to reuse the input element, which then doesn't get intercepted by Arrive.js.

Unfortunately the JS shipped with this project isn't really meant to be used with frameworks like these, because they need to take control of the DOM to properly work.

It may be easier to re-implement the JS functionality in Angular.

This is definitely still an issue using plain JS. Here is an example using the simplest code I can come up with: https://codepen.io/anon/pen/jKayvw?editors=1010

Angular is not the problem.

@n1474335 you are messing with the DOM when you use the innerHTML in that way.

https://codepen.io/FezVrasta/pen/eKegXK?editors=1010

Yes, good point. The issue still stands though. If you add a checkbox after a switch, only the label shows up.

@FezVrasta @n1474335 The buggy checkbox in the above codepen has a <span class="bmd-switch-track"></span> directly next to the checkbox. Sounds like that's an element that's meant to be part of a switch, which definitely makes it sound like a bmd bug.

Is there a work around to this?

Any news on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexanderPilhar picture AlexanderPilhar  路  3Comments

migaber picture migaber  路  10Comments

dmwyatt picture dmwyatt  路  3Comments

Elisa1202 picture Elisa1202  路  5Comments

snessnes picture snessnes  路  7Comments