MyBB Hacks

Full Version: How to add a new Input Field Type?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
OK thanks for the interest in this guys, I will try the things mentioned and report back.
OK I made the modifications. My code in my template looks like:

Code:
{$headerinclude}
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/post.js?ver=1800"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/datepicker-en-GB.js"></script>
<script type="text/javascript">
  jQuery(function() {
  	jQuery("#datepicker").datepicker(
		{ dateFormat: "dd/mm/yyyy" }).val()
  	$.datepicker.setDefaults($.datepicker.regional["en-GB"]);
  });
</script>


Text mask filter: Date (dd/mm/yyyy)
Input formatter: <?=strtotime({VALUE})?>
Input field html: <input type="text" class="textbox"{NAME_PROP}{MAXLEN_PROP}{WIDTH_PROP_SIZE}{TABINDEX_PROP}{REQUIRED_PROP} value="{VALUE}" id="datepicker" />
Display parsing: plain text
Display format: <?=date('d-m-Y', {VALUE})?>

However I have two problems:
1) The jquery datepicker is being obscured by the message section. I guess this is something to do with some CSS code?
2) When I select a date, it enters it into the textbox like: "18/09/20152015" instead of like "18/09/2015" (which is what I want)

Any ideas whats wrong? Cheers!

Have you tried it exactly as nier3 suggested it? She gives a full list of the custom field options.

For the date picker,yes, the z-index is too low - you need to set it at about 10000 to go over the sceditor
OK I fixed the z-index issue by adding style="position: relative; z-index: 10000;" to the input field html.
Everything else is the same as nier3 said, but I've made the date order dd/mm/yyyy like I want it to be.
OK the datepicker thing thinks "yy" means "yyyy", so that's fixed.
(09-17-2015 06:31 AM)RateU Wrote: [ -> ]Very nice Smile

I just want to add an idea to work also (hopefully) when editing draft and post preview (or when inline post error triggered):

Code:
<if (THIS_SCRIPT == 'editpost.php' && !$mybb->input['my_post_key']) || (THIS_SCRIPT == 'newthread.php' && $mybb->input['action'] == 'editdraft') then><?=date('m/d/Y',{VALUE})?><else>{VALUE}</if>


Also (if not saving it as string), maybe it is better (in my opinion) to set the Underlying Data Type to Integer.

I use pikaday though.


Hi RateU, I tried the code but doesn't work Frown

For now I'm using this:

Code:
<if THIS_SCRIPT == 'editpost.php' && !$GLOBALS['threadfields']['datexp'] then>

<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<?=date('Y/m/d', (int){VALUE})?>" id="datepicker" placeholder="editpost" />

<else>

<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="{VALUE}" id="datepicker" placeholder="newthread" />

</if>


With this the problem still is if user doesn't add a date in the field and I edit (and then save) the thread I have "1970/01/01" date instead of an empty field.

For the rest is ok: if I create a new thread I haven't problem; if I edit a thread with an existent date I have correct date (and not a string like before).

Date in preview post doesn't work Frown

Oh, so this is not a required field?
Maybe you can try this condition:

Code:
<if {VALUE} && !$mybb->input['my_post_key'] then><?=my_date('d-m-Y',{VALUE})?><else>{VALUE}</if>


The implementation is something like this:

HTML Code
<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<if {VALUE} && !$mybb->input['my_post_key'] then><?=my_date('d-m-Y',{VALUE})?><else>{VALUE}</if>" id="datepicker" />
<link type="text/css" rel="stylesheet" href="cache/jquery-ui/jquery-ui.min.css" />
<script src="cache/jquery-ui/jquery-ui.min.js"></script>
<script>
	$(function(){$('#datepicker').datepicker({dateFormat:'dd-mm-yy',autoSize:true});});
</script>

I tried all combinations of format date but only this works Frown

Code:
<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<if {VALUE} && !$mybb->input['my_post_key'] then><?=my_date('Y/m/d',{VALUE})?><else>{VALUE}</if>" id="datepicker" />
<link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="/datepicker-it.js"></script>
<script>
	$(function(){$('#datepicker').datepicker({dateFormat:'yy/mm/dd',autoSize:true});});
</script>


Other format dates, when I do preview thread or submit thread, it says Invalid value. It works only with Y/m/d Frown

But on showthread the format date is correct, that is dd-mm-yy because in Display Format I use <?=date('d-m-Y', {VALUE})?> so it's a problem only in newthread / edit post, but always better that string of before Biggrin Not a big problem

And now if I don't add a date and I edit the thread it's perfect, I haven't more 1970-01-01 so it's awesome Biggrin Yipi Yipi Thanks

(09-22-2015 09:29 AM)nier3 Wrote: [ -> ]when I do preview thread or submit thread, it says Invalid value. It works only with Y/m/d Frown

Probably because of this:
(09-16-2015 10:25 PM)nier3 Wrote: [ -> ]Text Mask Filter: Custom (regex) and write this: ^((?:19|20)\d\d)/(0?[1-9]|1[012])/(0?[1-9]|[12]\d|3[01])$

I use this Custom (regex) Text Mask Filter:

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

It is based on the default XThreads Date (dd/mm/yyyy) Text Mask Filter.

With this I have again error "Invalid value", when I create new thread and when I edit a thread Frown

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

Input Formatter: <?=strtotime({VALUE})?>

Input Field HTML:

Code:
<input type="text" class="textbox"{NAME_PROP}{MAXLE​​N_PROP}{WIDTH_PROP_SIZE}{TABINDE​X​_PROP}{REQUIRED_PROP} value="<if {VALUE} && !$mybb->input['my_post_key'] then><?=my_date('dd/mm/yyyy',{VALUE})?><else>{VALUE}</if>" id="datepicker" />


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

This custom thread field isn't required.


In the template:

Code:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  <script src="/datepicker-it.js"></script>
  
<script type="text/javascript">
jQuery(function() {
jQuery("#datepicker").datepicker({ dateFormat: "dd/mm/yyyy" }).val()
$.datepicker.setDefaults($.datepicker.regional['it']);
});
</script>


I need string number in database for move automatically threads every day on date of expiration:

Code:
if ($result = @$mysqli->query("UPDATE mybb_threads 
    LEFT JOIN mybb_threadfields_data
    ON mybb_threads.tid=mybb_threadfields_data.tid
    SET mybb_threads.fid='130' WHERE mybb_threads.fid IN('128','73') AND mybb_threadfields_data.datexp > 0 AND mybb_threadfields_data.datexp < UNIX_TIMESTAMP(NOW())"))

Pages: 1 2 3
Reference URL's