Topic: How to initialize the MDB checkbox.
codewiseio pro asked 6 years ago
/* add the material javascript after making DOM changes */ $.getScript('js/mdb.js', function() { jQuery('.mdb-select').material_select(); jQuery('input[type="checkbox"]').checkbox(); });
cad-development free answered 5 years ago
Again thanks for the replies.
I am not trying to set anything up inside of a dropdown. I only mentioned this as the dropdown object has a way of initialising via $({selector}).material_select();
I am calling Ajax and bringing back html to place in a DIV, I do not want to be creating items via JS. The code for an example checkbox would be:
<div class="form-check">
<input type="checkbox" class="form-check-input image-send-now" id="imageSendNow"<?php echo ($productPrint->getLoadImageNow()) ? ' checked' : '';?>>
<label class="form-check-label" for="imageSendNow">I wish to upload an image now</label>
With this no checkbox is rendered, so I am assuming that an initialisation is requires similar to 'material_select'. Or an I missing something?
lemons free commented 5 years ago
the closing div and the proper css include. As checkboxes don't need to be initialized I would check the complete div with your browsers dev tools. Also you could add an other checkbox somewhere else just to check if this error is caused by something else...
Grzegorz Bujański staff commented 4 years ago
I checked your code here: https://mdbootstrap.com/snippets/jquery/grzegorz-bujanski/1664536 And works fine. I only removed php code and added closing div. Do you have any errors in your browser dev tools?
cad-development free commented 4 years ago
Thank you both. I did have closing DIV just bad copy pasting. I will look a little deeper and comment out some code to see where the error is coming about. Thanks to both of you for taking the time. It is appreciated.
cad-development free answered 5 years ago
Any update on this?
I require to initialise checkboxes after an Ajax load.
lemons free commented 5 years ago
you don't need to initalize them, just take care to keep the structure of the docs, including the label.
Grzegorz Bujański staff commented 5 years ago
Hi @cad-development. As @lemons say, you don't need initialize checkbox.
Best, Grzegorz
cad-development free commented 5 years ago
Thanks for the reply Lemons and Grzegorz Bujański . In my case I do believe I need to initialise them as they do not render/show.
I am bringing back checkboxes as part of an Ajax call. I think this may be similar to drop-downs which do have a way of initialising.
lemons free commented 5 years ago
I forked my AJAX search snippet to show the dynamically added checkboxes. If you get the checkboxes itself from AJAX, double-check the MDB structure of the checkboxes. the LABEL is REQUIRED, even if empty:https://mdbootstrap.com/snippets/jquery/lhock/1656204
Grzegorz Bujański staff commented 5 years ago
I would only add value['title'] inside the label, not after $checkbox
lemons free commented 5 years ago
I know :), I just wanted to show that the label is required, even when empty...
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.5.10
- Device: PC
- Browser: Chrome
- OS: Ubuntu
- Provided sample code: No
- Provided link: No
Bartłomiej Malanowski staff commented 6 years ago
Could you please share more of your code with us?