How to set a dafault date value for a date input field?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
pilandros
Veteran Member
Posts: 98
Joined: 2014-02-13 18:19

How to set a dafault date value for a date input field?

Post by pilandros » 2015-12-14 21:39

I have an application to record tasks which are saved on an agenda table, where each record is a task to run with it's own data.
I also have a full month view of a calendar, and I need to allow the operator to add a new record in some specific date by just clicking on that date.
Sprite123414.jpg
Sprite123414.jpg (66.21 KiB) Viewed 5888 times
I can customize that link to open the table and get into the add function with a link like this: "http://myserver/agenda_view.php?addNew_x=1"
but then, the default date will always be the "today" date (or whatever default value I have placed into the appgini parameters).

To make this default value dynamically set, I need to send in the link, the date of the calendar-day-clicked.
In other words, what is the name of the variable to get a default value for a date field? is this possible?

I already have tryed several ways which none of them works:
(where $add_date has the value of ie. 2015-12-30 as well as $add_year, $add_month, $add_day which are "2015","12","30")
"http://myserver/agenda_view.php?addNew_ ... =$add_Date"
"http://myserver/agenda_view.php?addNew_ ... =$add_date"
"http://myserver/agenda_view.php?addNew_ ... y=$add_day"

Anybody that have tried this?

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: How to set a dafault date value for a date input field?

Post by a.gneady » 2016-01-03 16:47

Your AppGini application won't handle the date parameter you send to the page. You have to add code (possibly to the tablename_dv hook) to retrieve the parameter and then set the date field value to that parameter. Maybe this would work (but I didn't test it) if you put it in the tablename_dv function:

Code: Select all

$date_ts = strtotime($_GET['date']);
$date_day = date('j', $date_ts);
$date_month = date('n', $date_ts);
$date_year = date('Y', $date_ts);

$html .= "<script>\$j(function(){
    \$j('#TaskDate-dd').val('$date_day');
    \$j('#TaskDate-mm').val('$date_month');
    \$j('#TaskDate').val('$date_year');
});</script>";
Replace 'TaskDate' in the above code with the actual date field name.
:idea: AppGini plugins to add more power to your apps:

User avatar
pilandros
Veteran Member
Posts: 98
Joined: 2014-02-13 18:19

Re: How to set a dafault date value for a date input field?

Post by pilandros » 2016-04-04 19:16

Sorry for my late response to your much appreciated code but I forgot to thank you Ahmed,
That routine worked perfectly!

User avatar
a.gneady
Site Admin
Posts: 1354
Joined: 2012-09-27 14:46
Contact:

Re: How to set a dafault date value for a date input field?

Post by a.gneady » 2016-04-05 12:37

You're always welcome :D
:idea: AppGini plugins to add more power to your apps:

Post Reply