Codeigniter: set_select() form validation for birthday picker jquery plugin - php

Can anyone help me to figure out how can I use the set_select() Form helper in the birthday picker jquery plugin? What i want is if the validation fails the selected month, day and year stay after the page loads. Supposed to be the code needs to be injected in the option for the month only dropdown is
<?php echo set_select('birth[month]', 'here is the value but it is dynamically generated by the plugin','the condition for update function in the future'); ?>
I already figured out to select the dropdowns based on the value in the database using for update function by setting the database value to a hidden input and getting the value through jquery
$('select.birthMonth').find('[value='+myvariable+']').prop('selected',true);
The only problem is when the form validation fails birthdaypicker dropdowns reset to the default values. I cant use jquery to inject the
<?php echo set_select('birth[month]', 'here is the value but it is dynamically generated by the plugin','the condition for update function in the future'); ?>
since the second parameter supposed to be for
set_select
is generated by jquery.
Note : im having problem with month, day and year. if i can figure the month only then it would be easy for other dropdowns. Days also vary per month.
If there are any alternatives other than this plugin, please feel free to comment

set_select is an helper to generate your selects, it's run BEFORE the view is rendered and your jquery is of course initialized after.
You can't use it here, you have to let the plugin handle the select boxes on its own.
According to the plugin's documentation page, you can set "defaultDate" when you initialize the plugin. My recommendation would be something like this when initializing your plugin (in javascript):
'var date = '.$this->input->post("year").'-'.$this->input->post("month").'-'.$this->input->post("day").';
$("#demo").birthdayPicker({
defaultDate: date,
});'
You might need to check the value of date before actually using it, I made this quickly.

Related

How to pass date picker from one page to another

how can i pass a date picker from one page to another page and according to that how can I fetch data from database using PHP to display it?
UPDATE
Firstly, i just want to said that i use PDO to access the database.
Second, i dont use session method because i just want to make it simple.
after read the comment, i thing that i need to learn about get and post method. After learn about get and post method, now i can send the data from one page to other page. i also can sent data in form that phpmyadmin can read.
Thanks.
You will have to submit data when going on to another page. Date picker is essentially a front-end handler for a form input. As any form element it needs to be submitted (via GET or POST). On you receiving script (form action=). You can either, store it to DB as any other variable value as it will be available in $_GET or $_POST as a text variable, or just use that value to populate your date picker on the next page if you do not need to store it on this step.
If you need any additional help with any of the steps: form submission, DB queries, populating date pickers, please show us your attempts to achieve the result and we will be able to guide you towards the right direction.
You can get datepicker value depends your methods post and get and your input name.
for example if your code is
<form method="post" action="resp.php">
<input class="timepicker logs-datepicker" name="from_date" value="" type="text">
<input type="submit">
</form>
in resp.php page
$time = $_POST['from_date'];
and for change to timestamp
$time = strtotime($time,' 00:00:00');

multi datepicker to get dates from input field?

so my problem is this. I use the multi datepicker, http://multidatespickr.sourceforge.net/
for a site with news block. i save multiple dates for 1 news item and it works like a charm with php. BUT now my problem is, if someone wants to edit the news , I do get the current dates the news has, in a input field, but that isn't marked on the multi datepicker. problem here is, if they selected 30 dates, and want to exclude one after editing, they have to pick 29 dates again on datepicker, cause they wouldn't be active otherwise. my question here is, is there any way to make the datepicker get the dates from an input field ? FYI I get the same date formats both on getting and selecting from datepicker.
You'll have to show the context in which you use it, but the addDates parameter looks like it does what you want, so on instantiation you would pick up the list of dates from your input field and supply them in this parameter. See also how to pre-select dates.
I'm surprised the datepicker isn't permanently alive and just shows itself, in which case it would know what state it was in from last time it was hidden.
Update: reading even further it seems it uses the dates from an input field anyway. See this demo further in the instructions

jQuery UI Datepicker - Being able to pick day or month

I'd like to know if there is any way to be able to select a whole month in jQuery UI's Datepicker while still being able to select a single day.
I tried 'hacking' it by adding an onClick event to the title div after page load, but switching months seems to completely replace the div, thus losing the onClick.
Are there any other solutions? Or maybe an alternative which offers this option?
Your onClick event should be enough. You just need to use a jQuery event handler that works for dynamic links.
If < jQuery 1.7, use: live()
Else If >= jQuery 1.7, use: on()
If you don't necessarily need it to happen in one datepicker, it might be less confusing to have two of them. Use one to select the start date, and use the other one to select the end date. Once the dates are selected, you will need validation to be sure the selected end date is not before the start date (assuming you want that behavior).
To convert jQuery date picker into mont picker will leads to you bulky code. There are many ways to do this the best one is to hide date blocks by a function over riding method. Any way you can use this plugin for month / year picker.
http://lucianocosta.info/jquery.mtz.monthpicker/
i thing you can but Datepicker in div id="anything"
then use live event click like this without hacking any original code
$("#anything .ui-datepicker-month").live('click',function(){
do any thing :) ;
});
I think this has already been posted here
jQuery UI DatePicker to show month year only
very similar but same effect essentially any date selected in the month displays the month only

Jquery Calander: While loading the page calendar should be selected the range based on Start_date and End_Date input

I am using Jquery Datepicker. In on of my module (PHP) when i am trying to add package details i need to show the date picker with already selected dates in other color. So that admin will not use those selected dates for new package.
Please help me. Thanks in advance.
Regards,
Prabu
I'm not clear on whether you're trying to limit the selection to a specific date range, or whether you want to disable arbitrary dates within a range.
If it's the former, you should be able to specify minDate and maxDate when initialising datepicker. See here.
If the latter, you should be able to use the beforeShowDay option. There's a nice explanation on this question. The second element of the return value is a class name - using that with some corresponding CSS will allow you to see the colour. You can stop it being selected at all by returning false as the first element of the return value.

Trying to find a (jquery?) popup date/time selector with callback to php

I have a large table with input boxes.
Three columns of these are dates/times (in unix format).
Im trying to find an easy to implement way of allowing the user to click on this box, being able to (graphically) select a date/time, and when done, sending the selection to a php script to make the physical changes of the data. (i can convert the date/time back to unix from here if necessary).
The caveat is that each input is named dynamically according to its row number.
Here is my script where i output the date fields
}elseif(in_array($j, array(19,33,54))){
echo "<td><input type=text value=\"$value\" name=\"date$j\" class=med></td></td>";
jQuery UI datepicker supports a great number of options and events including an on-select event. It's also possible to have a datepicker attached to a hidden input with a separate activation control, so there's no problem at all with using it for AJAX.
Try to integrate the jQuery datepicker, but what you need to do is some kind of ajax call to the PHP!

Categories