icheckJs sometimes not showing

I’m using this plugin: https://github.com/dargullin/icheck

I’m using this in a Laravel + Vue app.

I already have included icheck and jquery in my bootstrap.js

window.$ = window.jQuery = require('jquery');
require('icheck/icheck.min.js');

I have this in my app.js:

$(document).ready(function(){
    $('input:not(#nonIcheck)').iCheck({
	    checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
	}).on('ifChecked', function(event){
        this.dispatchEvent(new Event("change"));	
	}).on('ifUnchecked', function(event){
		this.dispatchEvent(new Event("change"));
	});
});

Sometimes, it’s working, but sometimes, I noticed that the $('input:not(#nonIcheck)') doesn’t get all the elements needed, it returns a 0 length, so I’m only getting the native checkbox/radio buttons. Is there a way to fix this?

… how many fields are you marking as nonICheck? Because… that’s an ID selector. Which will probably still work in jQuery’s form, but… bad code form in general, if you’ve got multiple things with the same ID.

Also, surely this should only check inputs whose type are radio or checkbox, no?

I only have one checkbox that has an id of nonIcheck.

Yes, according to its docs, it will search for checkboxes and radio.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.