Date value returning 'null'

This forum contains topics that were moved from Get Satisfaction
Chris Flowers6766842
Posts: 0
Joined: Thu Mar 27, 2014 8:26 pm

Date value returning 'null'

Post by Chris Flowers6766842 »

Hello

I have a datepicker component called 'date' with an event set up whereby on value change it sets to local storage. I have it's property name set as 'date value'.

On the same page, I have an on page load event to run the following JS to set today's date by default:

var dateElement = Appery("date");
dateElement.setProperty("defaultDateValue", $.datepicker.formatDate(dateElement.datepicker_dataPickerOptions.dateFormat, new Date()));

So I wanted this to work whereby if the user selects no date, today's date is stored to local storage.

I then use the following code in SendGrid's 'before send event' 'text' field (along with the storage mappings):

var project = "Project: " + localStorage.getItem("project") + "\n";
var description = "Description: " + localStorage.getItem("description") + "\n";
var email = "Email: " + localStorage.getItem("email") + "\n";
var company = "Company: " + localStorage.getItem("company") + "\n";
var lifeguard_name = "Lifeguard Name: " + localStorage.getItem("lifeguard_name") + "\n";
var date = "Date: " + localStorage.getItem("date") + "\n";
var what_you_did = "What You Did: " + localStorage.getItem("what_you_did") + "\n";
var job_title = "Job Title: " + localStorage.getItem("job_title") + "\n";
var tel_number = "Telephone No.: " + localStorage.getItem("tel_number") + "\n";
var site = "Site: " + localStorage.getItem("site") + "\n";
var project_manager = "Project Manager: " + localStorage.getItem("project_manager") + "\n";
var role = "Role: " + localStorage.getItem("role") + "\n";

return project + description + email + company + lifeguard_name + date + what_you_did + job_title + tel_number + site + project_manager + role;

This all works perfectly except for the 'date' part. In the resulting email it appears like this:

Date: null

This only happens if the user DOES NOT select a date. If the user selects a date, it'll appear correctly.

Why is local storage no storing today's date on no user input? Why is it returning 'null'?

Many thanks for your help and kindness.

Chris Flowers6766842
Posts: 0
Joined: Thu Mar 27, 2014 8:26 pm

Date value returning 'null'

Post by Chris Flowers6766842 »

Really irritating me now this little bug!!

Chris Flowers6766842
Posts: 0
Joined: Thu Mar 27, 2014 8:26 pm

Date value returning 'null'

Post by Chris Flowers6766842 »

Ok sorted it!

Added:

localStorage.setItem('date', $('[dsid="date"] input').val());

To the JS on page load I already had (see above). Don't know why sorting it out via even on the datepicker itself wasn't working, but this definitely does now.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Date value returning 'null'

Post by Kateryna Grynko »

Hi Chris,

Thank you for the update! Glad it works.

Post Reply