Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Issue with pickaday in custom thread field
Verilog Offline
Member
***
Posts: 50
Joined: Nov 2013
Post: #1
Issue with pickaday in custom thread field
Hi all,
I am trying to use pickaday jquery library in MyBB 1.8 as 1.8 has jquery inbuilt.
I modified my custom thread field with below option :-
Input Field Type : Textbox
Text Mask filter : DD/MM/YYYY
Custom Html -

Code:
<input type="text" class="textbox"{NAME_PROP}{MAXLEN_PROP}{WIDTH_PROP_SIZE}{TABINDEX_PROP}{REQUIRED_PROP} value="{VALUE}" id="datepicker" />

Display Format:

Code:
<?=date('d-m-Y', {VALUE})?>


In my newthread template, I am having following code :-

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<html>
<head>
<title>{$lang->newthread_in}</title>
{$headerinclude}
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/moment.js"></script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/pickaday.js"></script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/pickaday.jquery.js"></script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1813"></script>
</head>
<body>
{$header}
{$preview}
{$thread_errors}
{$attacherror}
{$moderation_notice}
<form action="newthread.php?fid={$fid}&amp;processed=1" method="post" enctype="multipart/form-data" name="input">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder tmob_hide">
<tr>
<td class="thead"><strong>{$lang->post_new_thread}</strong></td>
<td class="thead"><strong class="mobile_show">{$lang->post_new_thread}</strong></td>
</tr>
<tr>
<td class="trow2" width="20%"><strong>{$lang->thread_subject}</strong></td>
<td class="trow2">{$prefixselect}<input type="text" class="textbox" name="subject" size="30" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>
{$extra_threadfields}
{$modoptions}
{$captcha}
</table>
<br />
<div style="text-align:center"><input type="submit" class="button" name="submit" value="{$lang->post_thread}" tabindex="4" accesskey="s" /> </div>
<input type="hidden" name="action" value="do_newthread" />
<input type="hidden" name="posthash" value="{$posthash}" />
<input type="hidden" name="attachmentaid" value="" />
<input type="hidden" name="attachmentact" value="" />
<input type="hidden" name="quoted_ids" value="{$quoted_ids}" />
<input type="hidden" name="tid" value="{$tid}" />
</form>
{$forumrules}
{$footer}
<script type="text/javascript">
    var picker = new Pikaday(
    {
        field: document.getElementById('datepicker'),
        firstDay: 1,
        minDate: new Date(2000, 0, 1),
        maxDate: new Date(2020, 12, 31),
        yearRange: [2000,2020],
        onSelect: function() {
            document.getElementById('datepicker').value = this.getMoment().format('DD/MM/YYYY');
        }
    });   
    picker.setMoment(moment().dayOfYear(366));    
</script>
</body>
</html>


I am able to see the datepicker properly but once I submit the thread, I see NULL getting stored in database, which I feel should not show as nulled.

Anyone can tell what might be wrong ?

01-09-2018 07:29 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #2
RE: Issue with pickaday in custom thread field
(01-09-2018 07:29 PM)Verilog Wrote:  I am able to see the datepicker properly but once I submit the thread, I see NULL getting stored in database, which I feel should not show as nulled.

Are you sure it is stored as NULL in the right column on your threadfields_data table?

01-10-2018 12:11 AM
Find all posts by this user Quote this message in a reply
Verilog Offline
Member
***
Posts: 50
Joined: Nov 2013
Post: #3
RE: Issue with pickaday in custom thread field
(01-10-2018 12:11 AM)RateU Wrote:  
(01-09-2018 07:29 PM)Verilog Wrote:  I am able to see the datepicker properly but once I submit the thread, I see NULL getting stored in database, which I feel should not show as nulled.

Are you sure it is stored as NULL in the right column on your threadfields_data table?

It is storing 0 now, I changed the js code previously and didn't check in phpMyAdmin.
01-10-2018 12:50 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: Issue with pickaday in custom thread field
You set the Underlying Data Type to Integer (you need to save it as Unix timestamp)?

(This post was last modified: 01-10-2018 01:20 AM by RateU.)
01-10-2018 01:10 AM
Find all posts by this user Quote this message in a reply
Verilog Offline
Member
***
Posts: 50
Joined: Nov 2013
Post: #5
RE: Issue with pickaday in custom thread field
(01-10-2018 01:10 AM)RateU Wrote:  You set the Underlying Data Type to Integer (you need to save it as Unix timestamp)?
Yes, it is set as integer. I am not sure how will I store that
I searched on stackoverflow for this but couldn't see how to implement this with custom thread field
https://stackoverflow.com/questions/3990...https://stackoverflow.com/questions/39904326/how-to-store-unix-timestamps-
01-10-2018 01:49 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: Issue with pickaday in custom thread field
Then you need to modify the value before it is saved into database. Use Input Formatter setting.
You can use strtotime function.

Note that strtotime will assume any xx/yy/zzzz as mm/dd/yyyy format, and xx-yy-zzzz as dd-mm-yyyy format.
http://php.net/manual/en/function.strtotime.php

01-10-2018 02:01 AM
Find all posts by this user Quote this message in a reply
Verilog Offline
Member
***
Posts: 50
Joined: Nov 2013
Post: #7
RE: Issue with pickaday in custom thread field
Awesomeness Smile
It worked, i changed my js also to MM/DD/YYYY
I didn't find default regex option in Xthreads for DD-MM-YYYY
01-10-2018 02:13 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: Issue with pickaday in custom thread field
If you want it as dd-mm-yyyy, you can set it to Custom (regex):

Code:
^(0?[1-9]|[12]\d|3[01])\-(0?[1-9]|1[012])\-((?:19|20)\d\d)$

It is basically only change the / delimiter to - from the original dd/mm/yyyy


01-10-2018 02:17 AM
Find all posts by this user Quote this message in a reply
Verilog Offline
Member
***
Posts: 50
Joined: Nov 2013
Post: #9
RE: Issue with pickaday in custom thread field
(01-10-2018 02:17 AM)RateU Wrote:  If you want it as dd-mm-yyyy, you can set it to Custom (regex):

Code:
^(0?[1-9]|[12]\d|3[01])\-(0?[1-9]|1[012])\-((?:19|20)\d\d)$

It is basically only change the / delimiter to - from the original dd/mm/yyyy

Thank you Smile
I am wondering now if I will be able to do sorting based on date if I store using ddmmyyyyy
01-10-2018 02:24 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #10
RE: Issue with pickaday in custom thread field
If you save it as Unix timestamp, it should be able to be sorted.

01-10-2018 02:35 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: