Date validation

pkjoshi

Active Member
Hi, I am trying to use the element plugin

IsNot on a date element.
> $today;
>NOW();

But none of this is working.
 
sorry can you describe in more detail what you are doing? I don't understand :)
 
I am trying to use validation on a element of type "date". What I want is that user shouldn't be able to select a date greater than today.
 
There's many ways to skin that cat, but I'd do this, with a PHP validation:

PHP:
$shortdate_time = strtotime(date('Y-m-d', strtotime($data)));
$today_time = strtotime(date('Y-m-d'));
return $shortdate_time <= $today_time;

That goes in the PHP box, NOT the "Condition" box.

-- hugh
 
or since today I've added a parameter to the date element which is a JS snippet which determines if a date is selectable or not. The hover text gives you an example of how to disallow future dates, inverting the code should give you what you want
 
Yes there is a new "Allow Date Function" field. There is some instructions as well, but I really can't get it to function to disallow for future date selection.

A little example will really help. Thanks.
 
did you read the hover text? If so what part of that needs more explaining:

"An eval'd piece of Javascript code, which is run on each day when the calendar is displayed

You have access to the 'date' variable which is the date being tested.

set a variable called 'return' to true to stop this date from being selected.

set a variable called 'return' to false to allow this date to be selected.

e.g. to only allow future dates to be selected:

var diff = new Date().compare(new Date(date));
var result = diff < 0 ? true : false;
 
There's many ways to skin that cat, but I'd do this, with a PHP validation:

PHP:
$shortdate_time = strtotime(date('Y-m-d', strtotime($data)));
$today_time = strtotime(date('Y-m-d'));
return $shortdate_time <= $today_time;
That goes in the PHP box, NOT the "Condition" box.

-- hugh

Thanks Hugh!
 
I have added the Allow date function as given, but does it get applied to all the date elements in the form?

For eg. there are 3 date elements
1) req_date: This date element automatically gets generated as the user adds a form

2) disp_date: This element has the option for the user to select the date. But the Calendar does not pop-up. Then i removed Allow date function from req_date, then there is a pop-up of the calendar.

What i require is the req_date should not be editable while the disp_date is a selection of the date from the calendar.

Pls help....
 
Can you explain what you have done so far, your question seems to be something other than what this thread is discussing?
Can you point us at the page as well, that always helps in disucssing the issue

thx
Rob
 
Hello Rob,

My config for the 2 elements are as follows:

1) date: This element is the date and time generated of the current time when the form is added without user able to select the date and time:

List Format: %d-%m-%Y %H:%M
Form Format: %d-%m-%Y %H:%M

Default to current date: Yes
Always return todays date: Yes

Allow Date Function:
var diff = new Date().compare(new Date(date));
var result = diff < 0 ? true : false;
var result = true;

2) Delivery_Date: This element is the date and time that the user can select

Allow Date Function:
var diff = new Date().compare(new Date(date));
var result = diff > 0 ? true : false;

The other above setting remains the same. Basically, i need that the Date picker / calendar pop-up, which shows when clicked, should not display in the form for the "date" element while it should display for Delivery_Date. Presently, the current config gray out the calendar for "Date".
 
I'm a little confused ... according to the above, you are applying an 'allow date' function to the 'Date' element, which is the one you don't want the date picker showing for. The 'allow date' code is only used by the date picker, as a way to 'black out' certain dates on the calendar popup.

Have you tried just setting the element's write access so the element is read only for your normal users? That should prevent the date widget option from being displayed, but should still apply any default you set on the element.

-- hugh
 
I tried the same...the widget still pops up. but any way i think i can carry on with the widget completely grayed out.

Thank you team....
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top