MyBB Hacks

Full Version: Issue with pickaday in custom thread field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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:
<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)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)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.
You set the Underlying Data Type to Integer (you need to save it as Unix timestamp)?
(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-
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
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
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)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
If you save it as Unix timestamp, it should be able to be sorted.
Pages: 1 2
Reference URL's