inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 24, 2016 0:11:48 GMT -8
Would I be wise then to wrap my key set thingy into an if loop then? As then I could disable the checkbox in one fell swoop That would keep from setting the key however that would not disable the "Appearance" of the box being checked and unchecked. It just wouldn't do anything to your data. (So IF would be an "extra" level of security) I'm confused how a simple if ('box[.a]' is checked){ Keycode here [.checkbox[.a]].disabled } (not proper code but you get the picture) would stop the key from setting. When I say 'disable' the checkbox I mean I want to 'freeze' it how it is once its been checked so users can't accidentally untick it
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 24, 2016 1:47:01 GMT -8
That would keep from setting the key however that would not disable the "Appearance" of the box being checked and unchecked. It just wouldn't do anything to your data. (So IF would be an "extra" level of security) I'm confused how a simple if ('box[.a]' is checked){ Keycode here [.checkbox[.a]].disabled } (not proper code but you get the picture) would stop the key from setting. When I say 'disable' the checkbox I mean I want to 'freeze' it how it is once its been checked so users can't accidentally untick it You have good logic. But that .check box.a.disabled will actually end up being $(jquery selector).prop('disabled','disabled') That adds disabled=disabled to the check box so users can't use it anymore. I mentioned disabled as HTML previously.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 24, 2016 2:00:08 GMT -8
Okay so using an if statement won't stop the key setting or will it?
That's what I'm more concerned about as that will control as to just where I park the if statement
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 24, 2016 4:00:27 GMT -8
Okay so using an if statement won't stop the key setting or will it? That's what I'm more concerned about as that will control as to just where I park the if statement If can
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 24, 2016 23:06:01 GMT -8
Is there any way to simply hunt for checkboxes in just this plugin?
eg 'if in this plugin you find any checkbox is checked do this'
I'm not sure if 'this' would work in this case?
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 25, 2016 0:11:59 GMT -8
Is there any way to simply hunt for checkboxes in just this plugin? eg 'if in this plugin you find any checkbox is checked do this' I'm not sure if 'this' would work in this case? On all your checkboxes add a new class name and then search by the class $('.checkboxClass').each(function(){ var checked = $(this).is(':checked') })
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 25, 2016 0:17:00 GMT -8
how would I use this to then put it into an if statement to disable it? I'm trying to learn here
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 25, 2016 0:20:28 GMT -8
Is there any way to simply hunt for checkboxes in just this plugin? eg 'if in this plugin you find any checkbox is checked do this' I'm not sure if 'this' would work in this case? On all your checkboxes add a new class name and then search by the class $(jquery selector).prop('disabled',true) Boy_Wonder $('.checkboxClass').each(function(){ var checked = $(this).is(':checked') if(checked) $(this).prop('disabled',true) })
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 25, 2016 0:31:12 GMT -8
so let me break things down line by line so I can check what I'm understanding is right
$('.checkboxClass').each(function(){ Is this doing almost what a for loop would do, telling it to go through each thing with the class specified and apply the function?
var checked = $(this).is(':checked') This is setting a variable called checked, I'm going to assume that this will be setting it up that 'if this has the 'checked' addition
if(checked) $(this).prop('disabled',true) Using the variable it then tells it that if 'checked is true' according to the variable add the disabled property to it as well?
}) Closing the function
Am I right?
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 25, 2016 0:38:04 GMT -8
so let me break things down line by line so I can check what I'm understanding is right $('.checkboxClass').each(function(){ Is this doing almost what a for loop would do, telling it to go through each thing with the class specified and apply the function? var checked = $(this).is(':checked') This is setting a variable called checked, I'm going to assume that this will be setting it up that 'if this has the 'checked' addition if(checked) $(this).prop('disabled',true) Using the variable it then tells it that if 'checked is true' according to the variable add the disabled property to it as well? }) Closing the function Am I right? You are exactly correct. Jquery made their own version of the for() loop and called it .each() so that jquery selectors could remain in their $() wrapper using the word this instead of $(array[a]) is(checked) returns true if the property is checked and false if not if(checked) if statements only run if the end result is true, so its true continue .prop adds disabled to the item close
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 25, 2016 0:41:20 GMT -8
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 25, 2016 0:53:18 GMT -8
I try that and sometimes I don't understand so I come here to ask xD
|
|
inherit
216224
0
Aug 1, 2024 1:18:46 GMT -8
Quozzo
408
November 2014
quozzo
|
Post by Quozzo on Apr 25, 2016 1:08:50 GMT -8
Sorry to but in, but if there was one thing I could change, it would be to cache $(this) if you use it in a function more than once. I just do it by default now.
$('.checkboxClass').each(function(){ var $this = $(this), checked = $this.is(':checked'); if(checked) $this.prop('disabled',true); })
It will make the code run faster, not that you can tell with one code, but it adds up.
|
|
inherit
Peabrained Codebreaker
107114
0
Mar 11, 2020 7:47:27 GMT -8
Boy_Wonder
6,249
July 2007
natzy24
|
Post by Boy_Wonder on Apr 25, 2016 1:21:24 GMT -8
Apparently somewhere I have goofed
//P2 - Generate checkboxes to mark if a task has been done or not for(a=0;a<pb.plugin.get('to_do_list').settings.unapp_chkbox.length;a++){ $('#unapp').append('<input type="checkbox" id="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_id+'"class="checkboxy"value="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_label+'" ><label for="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_id+'">'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_label+'<br /></label></form>'); }
//P3 - Check if all checkboxes have been ticked and store to key. Each tickbox needs to store that its been ticked pb.plugin.key('ToDoListKey').set({ value:{'box1':1} }); $('.checkboxy').each(function(){ var checked = $(this).is(':checked') if(checked){ $(this).prop('disabled',true) } })
but its not disabling checkboxes
Also just so I can check data is being stored on the key is there anyway I can console log to output what it has saved in?
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Apr 25, 2016 1:46:10 GMT -8
Apparently somewhere I have goofed //P2 - Generate checkboxes to mark if a task has been done or not for(a=0;a<pb.plugin.get('to_do_list').settings.unapp_chkbox.length;a++){ $('#unapp').append('<input type="checkbox" id="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_id+'"class="checkboxy"value="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_label+'" ><label for="'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_id+'">'+pb.plugin.get('to_do_list').settings.unapp_chkbox[a].checkbox_label+'<br /></label></form>'); }
//P3 - Check if all checkboxes have been ticked and store to key. Each tickbox needs to store that its been ticked pb.plugin.key('ToDoListKey').set({ value:{'box1':1} }); $('.checkboxy').each(function(){ var checked = $(this).is(':checked') if(checked){ $(this).prop('disabled',true) } })
but its not disabling checkboxes Also just so I can check data is being stored on the key is there anyway I can console log to output what it has saved in? Of course its not going to disable your boxes lol. You are setting your key and checking if boxes are checked when the page is loaded. You need the key and disable script to run when it is being checked. Hint: Onclick=function()
|
|