inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Feb 23, 2016 10:37:39 GMT -8
I'm working on a plugin that uses a multi-dimensional array. The objective is to have the plugin come with some "common" dates and Events. Looking at the code P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ posted here, I've tried setting this up to which an autoform is used to append entries made in the UI to be cycled through as well. Here's what I've got: $('document').ready(function() { var now = new Date(); var today = (now.getMonth()+1)+"/"+now.getDate(); var eventList = [ ["1/1","New Year's Day"], ["2/14","Valentine's Day"], ["3/17","St. Patrick's Day"], ["6/14","Flag Day"], ["7/4","Independence Day"], ["10/31","Halloween"], ["11/11","Veteran's Day"], ["12/25","Christmas Day"] ]; if (msg_otd.length) for (i = 0, max = msg_otd.length; i < max; i++) eventList.push([pb.plugin.get('on_this_day').settings.msg_otd.otd_date,pb.plugin.get('on_this_day').settings.msg_otd.otd_desc]);
My question is, is my eventList.push statement correct in syntax? Since I'm appending to an array, I thought the square brackets would be needed to indicate it's an array entry. Note: This is just a rough draft. The actual eventList.push will look something like this when I've got those plugin settings assigned to variables: eventList.push([settings.msg_otd.otd_date,settings.msg_otd.otd_desc])
Thanks!
|
|
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 Feb 23, 2016 15:43:43 GMT -8
I'm working on a plugin that uses a multi-dimensional array. The objective is to have the plugin come with some "common" dates and Events. Looking at the code P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ posted here, I've tried setting this up to which an autoform is used to append entries made in the UI to be cycled through as well. Here's what I've got: $('document').ready(function() { var now = new Date(); var today = (now.getMonth()+1)+"/"+now.getDate(); var eventList = [ ["1/1","New Year's Day"], ["2/14","Valentine's Day"], ["3/17","St. Patrick's Day"], ["6/14","Flag Day"], ["7/4","Independence Day"], ["10/31","Halloween"], ["11/11","Veteran's Day"], ["12/25","Christmas Day"] ]; if (msg_otd.length) for (i = 0, max = msg_otd.length; i < max; i++) eventList.push([pb.plugin.get('on_this_day').settings.msg_otd.otd_date,pb.plugin.get('on_this_day').settings.msg_otd.otd_desc]);
My question is, is my eventList.push statement correct in syntax? Since I'm appending to an array, I thought the square brackets would be needed to indicate it's an array entry. Note: This is just a rough draft. The actual eventList.push will look something like this when I've got those plugin settings assigned to variables: eventList.push([settings.msg_otd.otd_date,settings.msg_otd.otd_desc])
Thanks! Well you got the push right but i assume you are using an auto form meaning everytime you see msg_otd u need msg_otd[i]
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Feb 23, 2016 17:40:06 GMT -8
So this: eventList.push([pb.plugin.get('on_this_day').settings.msg_otd.otd_date,pb.plugin.get('on_this_day').settings.msg_otd.otd_desc])
should be this: eventList.push([pb.plugin.get('on_this_day').settings.msg_otd[i].otd_date,pb.plugin.get('on_this_day').settings.msg_otd[i].otd_desc])
And, yes, I'm using autoforms. Thanks!
|
|
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 Feb 24, 2016 17:43:43 GMT -8
Actually, since I'm using a multi-dimensional array, shouldn't this line: eventList.push([pb.plugin.get('on_this_day').settings.msg_otd[i].otd_date,pb.plugin.get('on_this_day').settings.msg_otd[i].otd_desc])
actually be this (to place the date and description properly): eventList.push([pb.plugin.get('on_this_day').settings.msg_otd[i][0].otd_date,pb.plugin.get('on_this_day').settings.msg_otd[i][1].otd_desc])
Otherwise, it'll think it's a single dimension array - or just overwrite the dates with the descriptions (assuming using just msg_otd[i] would always overwrite msg_otd[i][0]). I tried to post yesterday via mobile but it didn't send and I wasn't about to phone type it back out lol. So the deal is that originally it was a multidimensional array. When you move it to the manage plugin section. You are making a single dimensional array and instead of using a multi array you are using an object. Therefore your structure actually looks like this when using : pb.plugin.get('on_this_day').settings.msg_otd is a single dimension array with objects inside pb.plugin.get('on_this_day').settings.msg_otd =[{otd_date:'1/1', otd_desc:'New Years Day'},{},{},{}] These objects contain your autoform names and user set values pb.plugin.get('on_this_day').settings.msg_otd[0] = {otd_date:'1/1', otd_desc:'New Years Day'}
pb.plugin.get('on_this_day').settings.msg_otd[0].otd_date='1/1'
pb.plugin.get('on_this_day').settings.msg_otd[0].otd_desc='New Years Day'
IF YOU ADDED SOMETHING IN THE AUTOFORM THAT ALLOWED MULTIPLE ANSWERS LIKE FORUM SEARCH IT WOULD BE: pb.plugin.get('on_this_day').settings.msg_otd =[{otd_date:'', otd_desc:'', group_search_box: [1,5,13]},{},{},{}]
THEN it would be an array with an object holding an array pb.plugin.get('on_this_day').settings.msg_otd[0].group_search_box[2] = 13
|
|
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 Feb 24, 2016 17:45:47 GMT -8
Also when you are pushing to your event list, you are making it back into a multi dimensional array because you are pushing encapsulated in Open[ and close] brackets
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Feb 24, 2016 17:49:29 GMT -8
Yeah - figured that out, why I deleted that post. Was hoping to delete it before anyone caught it. Oh well. Here's what I've got so far: // On This Date // Version: 1.0.0 // Created by: MSG // This header must remain intact and unedited.
$('document').ready(function() { var plugin = pb.plugin.get('on_this_date'); var settings = null; if (plugin && plugin.settings) { settings = plugin.settings; } if (settings) var now = new Date(); var today = (now.getMonth()+1)+"/"+now.getDate(); var eventList = [ ["1/1","New Year's Day"], ["2/14","Valentine's Day"], ["3/17","St. Patrick's Day"], ["6/14","Flag Day"], ["7/4","Independence Day"], ["10/31","Halloween"], ["11/11","Veteran's Day"], ["12/25","Christmas Day"] ]; var eventToday = []; var allEventsToday = ""; if (settings.msg_otd.length) { for (i = 0, max = settings.msg_otd.length; i < max; i++) eventList.push([settings.msg_otd[i].otd_date,settings.msg_otd[i].otd_desc]); } if (settings.msg_otd.length) { for (z = 0, max2 = settings.msg_otd.length; z < max2; Z++) if (settings.msg_otd[z].otd_date == today) eventToday.push([settings.msg_otd[z].otd_date,settings.msg_otd[z].otd_desc]); } if (eventToday.length == 1) { $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br /><b>'+settings.msg_otd[0].otd_date+'</b><br />'+settings.msg_otd[0].otd_desc+'<br /><br /></div>'); } else if (eventToday.length > 1) { for (y = 0, max3 = settings.msg_otd.length; y < max3; y++) allEventsToday += "<b>"+eventToday[y]+"</b><br />"+eventToday[y]+"<br /><br />"; $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br />'+allEventsToday+'</div>'); } else { return; } });
|
|
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 Feb 24, 2016 17:54:26 GMT -8
Yeah - figured that out, why I deleted that post. Was hoping to delete it before anyone caught it. Oh well. Here's what I've got so far: // On This Date // Version: 1.0.0 // Created by: MSG // This header must remain intact and unedited.
$('document').ready(function() { var plugin = pb.plugin.get('on_this_date'); var settings = null; if (plugin && plugin.settings) { settings = plugin.settings; } if (settings) var now = new Date(); var today = (now.getMonth()+1)+"/"+now.getDate(); var eventList = [ ["1/1","New Year's Day"], ["2/14","Valentine's Day"], ["3/17","St. Patrick's Day"], ["6/14","Flag Day"], ["7/4","Independence Day"], ["10/31","Halloween"], ["11/11","Veteran's Day"], ["12/25","Christmas Day"] ]; var eventToday = []; var allEventsToday = ""; if (settings.msg_otd.length) { for (i = 0, max = settings.msg_otd.length; i < max; i++) eventList.push([settings.msg_otd[i].otd_date,settings.msg_otd[i].otd_desc]); } if (settings.msg_otd.length) { for (z = 0, max2 = settings.msg_otd.length; z < max2; Z++) if (settings.msg_otd[z].otd_date == today) eventToday.push([settings.msg_otd[z].otd_date,settings.msg_otd[z].otd_desc]); } if (eventToday.length == 1) { $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br /><b>'+settings.msg_otd[0].otd_date+'</b><br />'+settings.msg_otd[0].otd_desc+'<br /><br /></div>'); } else if (eventToday.length > 1) { for (y = 0, max3 = settings.msg_otd.length; y < max3; y++) allEventsToday += "<b>"+eventToday[y]+"</b><br />"+eventToday[y]+"<br /><br />"; $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br />'+allEventsToday+'</div>'); } else { return; } });
That should be your basic html <div class="container" id=""> <div class="title-bar"> <h2>My Title</h2> </div> <div class="content pad-all cap-bottom"> Content </div></div>
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Feb 24, 2016 18:06:22 GMT -8
// On This Date // Version: 1.0.0 // Created by: MSG // This header must remain intact and unedited.
$('document').ready(function() { var plugin = pb.plugin.get('on_this_date'); var settings = null; if (plugin && plugin.settings) { settings = plugin.settings; } if (settings) var now = new Date(); var today = (now.getMonth()+1)+"/"+now.getDate(); var eventList = [ ["1/1","New Year's Day"], ["2/14","Valentine's Day"], ["3/17","St. Patrick's Day"], ["6/14","Flag Day"], ["7/4","Independence Day"], ["10/31","Halloween"], ["11/11","Veteran's Day"], ["12/25","Christmas Day"] ]; var eventToday = []; var allEventsToday = ""; if (settings.msg_otd.length) { for (i = 0, max = settings.msg_otd.length; i < max; i++) eventList.push([settings.msg_otd[i].otd_date,settings.msg_otd[i].otd_desc]); } console.log(eventList); if (settings.msg_otd.length) { for (z = 0, max2 = settings.msg_otd.length; z < max2; z++) if (settings.msg_otd[z].otd_date == today) eventToday.push([settings.msg_otd[z].otd_date,settings.msg_otd[z].otd_desc]); } console.log(eventToday); if (eventToday.length == 1) { $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br /><b>'+settings.msg_otd[0].otd_date+'</b><br />'+settings.msg_otd[0].otd_desc+'<br /><br /></div>'); } else if (eventToday.length > 1) { for (y = 0, max3 = settings.msg_otd.length; y < max3; y++) allEventsToday += "<b>"+eventToday[y]+"</b><br />"+eventToday[y]+"<br /><br />"; $('.msg-otd').html('<div class="container"><div class="title-bar"><h2>On This Date</h2></div><br />'+allEventsToday+'</div>'); } else { return; } });
|
|
inherit
217348
0
Jul 27, 2022 7:26:44 GMT -8
Lynx
5,849
January 2015
msg
|
Post by Lynx on Feb 24, 2016 18:40:40 GMT -8
DONE! Posting a support thread now.
|
|
inherit
216224
0
Aug 1, 2024 1:18:46 GMT -8
Quozzo
408
November 2014
quozzo
|
Post by Quozzo on Mar 1, 2016 4:45:12 GMT -8
Should it only assign the `now` variable if the settings are truthy? Using curly braces, even on one line, should be used to prevent this kind of thing.
|
|
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 Mar 2, 2016 4:13:55 GMT -8
Should it only assign the `now` variable if the settings are truthy? Using curly braces, even on one line, should be used to prevent this kind of thing. Yeah I agree. That was one of the things he caught while we were talking.
|
|