#1 2017-02-28 14:21:51

Antonio.Cambule
Member
Registered: 2017-02-19
Posts: 38

Serialization (like in Agenda Example) and Casting for Num and Dates

Hi there,

I have a Date Input and a Number Input on my view.
I used the Agenda example to serialize/deserialize data in local storage.

To get the values into the inputs i use:

  
    // For number:
    ObjectGetProp "[Item]" "Count" "[TempNumber]"
    StrToNumber "[TempNumber]" "[CountInput.Value]"    

    // For date:
    ObjectGetProp "[Item]" "ExpirationDate" "[RecordDate]"
    NewDate "[RecordDate]" "" "[TempDate]"
    DateToJSDate "[TempDate]" "[ExpirationInput.Value]"

If do not cast the values i get errors.
So, is this the right way to go, do i need to cast them into the
correct types? Is there a an other approach to consider?

thanks and regards
Antonio

Offline

#2 2017-02-28 15:27:11

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Serialization (like in Agenda Example) and Casting for Num and Dates

Hello Antonio,

In principle, always that we use the "StrSerialize" action, then we must to use their counter part "StrUnserialize" in order to get the proper value. Said that, we only can serialize Arrays and Objects variables. In other words, strings and numbers can be saved without any serialization/unserialization.

If what we wanted is to save the value of an Input Date we can do something like this:

// Our Date Input is named "DateInput"
NewDate "[DateInput.Value]" "" "[Date]"

// Get the timestamp of the selected date
DateToUnix "[Date]" "[DateTimestamp]"

// Save the timestamp into the app's local storage
SetOption "SavedDate" "[DateTimestamp]" "Number"

Then, to recover that value and place it again into an Date Input control we can codify something like the below one:

// Get a previously saved date timestamp
GetOption "SavedDate" "[DateTimestamp]"

// If certainly we have some value here
If "[DateTimestamp]" "!=" ""

  // Prepare a new Date variable using the saved timestamp
  NewDate "[DateTimestamp]" "X" "[Date]"

  // Set the Date variable into the Data Input control
  DateToJSDate "[Date]" "[DateInput.Value]"
EndIf

Hope this can help in something!

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.