Reputation: 388
I'm wondering if there's a way to validate date from DatePicker in client side? I would like to compare the date from DatePicker with now date.
I see it seems only have validateLength()
, validateRange()
, etc.
But those seems not work for date.
Upvotes: 0
Views: 841
Reputation: 5051
An addValueChangeHandler
would work...
function doGet() {
var app = UiApp.createApplication();
var date = app.createDateBox().setId('date').setName('date');
var label = app.createLabel('').setId('status');
var handler = app.createServerHandler('checkDate').addCallbackElement(date);
date.addValueChangeHandler(handler)
app.add(date).add(label);
return app;
}
function checkDate(e) {
var app = UiApp.getActiveApplication();
var date = e.parameter.date;
var today = new Date().getTime();
if (date.getTime() < today)
app.getElementById('status').setText('Date is before today.');
else app.getElementById('status').setText('Date is after today.');
return app;
}
Upvotes: 0
Reputation: 1462
Afraid not. Either use server handlers or you write your UI in HtmlService so you can code your own client side validation without the client handler restrictions. Coding your own ui shouldn't be too much trouble, especially if you use something like jQuery UI for your widgets - here's an example.
Upvotes: 1