jQuery selectable() not responding to checkbox ticks

Multi tool use
Multi tool use












0















I've got a set of checkboxes which can all be checked/unchecked easily by dragging the mouse over the labels using selectable() plugin. But if I specifically click a checkbox input box instead of its label, nothing happens. I've tried all kinds of combinations using the filter, but nothing seems to work other than using 'label'. I want the behaviour to be the same whether the user drags over the input boxes or the labels. Several hours on this now, please help! Fiddle below.



<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>



$(".myBoxes").selectable({

filter: 'label',

stop: function() {
$(".ui-selected input", this).each(function() {
this.checked = !this.checked;

if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}

});
}
});



label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}


http://jsfiddle.net/y7xk032m/










share|improve this question























  • so you need a solution using this plugin?? or any solution??

    – Mohamed-Yousef
    Dec 30 '18 at 21:11
















0















I've got a set of checkboxes which can all be checked/unchecked easily by dragging the mouse over the labels using selectable() plugin. But if I specifically click a checkbox input box instead of its label, nothing happens. I've tried all kinds of combinations using the filter, but nothing seems to work other than using 'label'. I want the behaviour to be the same whether the user drags over the input boxes or the labels. Several hours on this now, please help! Fiddle below.



<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>



$(".myBoxes").selectable({

filter: 'label',

stop: function() {
$(".ui-selected input", this).each(function() {
this.checked = !this.checked;

if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}

});
}
});



label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}


http://jsfiddle.net/y7xk032m/










share|improve this question























  • so you need a solution using this plugin?? or any solution??

    – Mohamed-Yousef
    Dec 30 '18 at 21:11














0












0








0








I've got a set of checkboxes which can all be checked/unchecked easily by dragging the mouse over the labels using selectable() plugin. But if I specifically click a checkbox input box instead of its label, nothing happens. I've tried all kinds of combinations using the filter, but nothing seems to work other than using 'label'. I want the behaviour to be the same whether the user drags over the input boxes or the labels. Several hours on this now, please help! Fiddle below.



<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>



$(".myBoxes").selectable({

filter: 'label',

stop: function() {
$(".ui-selected input", this).each(function() {
this.checked = !this.checked;

if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}

});
}
});



label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}


http://jsfiddle.net/y7xk032m/










share|improve this question














I've got a set of checkboxes which can all be checked/unchecked easily by dragging the mouse over the labels using selectable() plugin. But if I specifically click a checkbox input box instead of its label, nothing happens. I've tried all kinds of combinations using the filter, but nothing seems to work other than using 'label'. I want the behaviour to be the same whether the user drags over the input boxes or the labels. Several hours on this now, please help! Fiddle below.



<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>



$(".myBoxes").selectable({

filter: 'label',

stop: function() {
$(".ui-selected input", this).each(function() {
this.checked = !this.checked;

if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}

});
}
});



label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}


http://jsfiddle.net/y7xk032m/







jquery jquery-ui-selectable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 30 '18 at 20:40









SilverburchSilverburch

177318




177318













  • so you need a solution using this plugin?? or any solution??

    – Mohamed-Yousef
    Dec 30 '18 at 21:11



















  • so you need a solution using this plugin?? or any solution??

    – Mohamed-Yousef
    Dec 30 '18 at 21:11

















so you need a solution using this plugin?? or any solution??

– Mohamed-Yousef
Dec 30 '18 at 21:11





so you need a solution using this plugin?? or any solution??

– Mohamed-Yousef
Dec 30 '18 at 21:11












2 Answers
2






active

oldest

votes


















1














The checkbox is another DOM over the div, so you must attach the same event to it like below:



$("input[type='checkbox']").click(function(event){
if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}
});


DemoL http://jsfiddle.net/86njvLrw/






share|improve this answer
























  • I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

    – Silverburch
    Dec 30 '18 at 22:22



















1














For Me I wouldn't use the selectable() I'll just use click() event .. Here is how






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





For reference you can take a look at jQuery difference between change and click event of checkbox






share|improve this answer


























  • Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

    – Silverburch
    Dec 30 '18 at 22:25











  • Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

    – Mohamed-Yousef
    Dec 30 '18 at 22:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53981256%2fjquery-selectable-not-responding-to-checkbox-ticks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The checkbox is another DOM over the div, so you must attach the same event to it like below:



$("input[type='checkbox']").click(function(event){
if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}
});


DemoL http://jsfiddle.net/86njvLrw/






share|improve this answer
























  • I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

    – Silverburch
    Dec 30 '18 at 22:22
















1














The checkbox is another DOM over the div, so you must attach the same event to it like below:



$("input[type='checkbox']").click(function(event){
if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}
});


DemoL http://jsfiddle.net/86njvLrw/






share|improve this answer
























  • I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

    – Silverburch
    Dec 30 '18 at 22:22














1












1








1







The checkbox is another DOM over the div, so you must attach the same event to it like below:



$("input[type='checkbox']").click(function(event){
if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}
});


DemoL http://jsfiddle.net/86njvLrw/






share|improve this answer













The checkbox is another DOM over the div, so you must attach the same event to it like below:



$("input[type='checkbox']").click(function(event){
if ($(this).is(':checked')) {
console.log($(this));
$(this).parent().addClass("LabelHighlight")
} else {
$(this).parent().removeClass("LabelHighlight")
}
});


DemoL http://jsfiddle.net/86njvLrw/







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 30 '18 at 21:15









WeiYuanWeiYuan

4,1141917




4,1141917













  • I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

    – Silverburch
    Dec 30 '18 at 22:22



















  • I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

    – Silverburch
    Dec 30 '18 at 22:22

















I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

– Silverburch
Dec 30 '18 at 22:22





I see, and thank you for your explanation. It does make the code long-winded but I understand that there's little alternative if I want to use this plugin.

– Silverburch
Dec 30 '18 at 22:22













1














For Me I wouldn't use the selectable() I'll just use click() event .. Here is how






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





For reference you can take a look at jQuery difference between change and click event of checkbox






share|improve this answer


























  • Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

    – Silverburch
    Dec 30 '18 at 22:25











  • Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

    – Mohamed-Yousef
    Dec 30 '18 at 22:36
















1














For Me I wouldn't use the selectable() I'll just use click() event .. Here is how






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





For reference you can take a look at jQuery difference between change and click event of checkbox






share|improve this answer


























  • Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

    – Silverburch
    Dec 30 '18 at 22:25











  • Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

    – Mohamed-Yousef
    Dec 30 '18 at 22:36














1












1








1







For Me I wouldn't use the selectable() I'll just use click() event .. Here is how






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





For reference you can take a look at jQuery difference between change and click event of checkbox






share|improve this answer















For Me I wouldn't use the selectable() I'll just use click() event .. Here is how






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





For reference you can take a look at jQuery difference between change and click event of checkbox






$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>





$('.myBoxes label').on('click' , function(e){
$("input:checkbox" , this).change();
});
$("input:checkbox").on("click" , function(e){
$(this).closest('label').toggleClass("LabelHighlight");
});

label {
display: block;
padding: 7px;
width: 120px;
margin-bottom: 14px;
border: 1px solid red;
}

label.ui-selecting {
background: lightgreen;
}

.LabelHighlight {
background: lightgreen;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>
<div class='myBoxes'>

<label>Check 1<input type="checkbox" id="chk1" /> </label>
<label>Check 2<input type="checkbox" id="chk2" /> </label>
<label>Check 3<input type="checkbox" id="chk3" /> </label>
<label>Check 4<input type="checkbox" id="chk4" /> </label>

</div>
</form>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 30 '18 at 21:39

























answered Dec 30 '18 at 21:29









Mohamed-YousefMohamed-Yousef

19.2k31122




19.2k31122













  • Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

    – Silverburch
    Dec 30 '18 at 22:25











  • Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

    – Mohamed-Yousef
    Dec 30 '18 at 22:36



















  • Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

    – Silverburch
    Dec 30 '18 at 22:25











  • Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

    – Mohamed-Yousef
    Dec 30 '18 at 22:36

















Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

– Silverburch
Dec 30 '18 at 22:25





Yes, this is what I had before the plugin. However, the dragging and lasso that's made possible by the plugin is excellent for my particular needs here, so I'd rather stick with it if at all possible.

– Silverburch
Dec 30 '18 at 22:25













Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

– Mohamed-Yousef
Dec 30 '18 at 22:36





Its OK @Silverburch if you'll use the plugin for another things .. I posted my answer 1st: I assume that you just need the plugin to do this thing .. 2nd: to let you know another way of how to do this without plugin .. anyways Have a great day :-)

– Mohamed-Yousef
Dec 30 '18 at 22:36


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53981256%2fjquery-selectable-not-responding-to-checkbox-ticks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







mOniPKB
bfofDyZDrqaSw9ms0qL,6,wi,9oiowRxuI6Y,nkYdSY7lLkpST

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas