forms-manager icon indicating copy to clipboard operation
forms-manager copied to clipboard

Add parse and serializer options for persistState

Open ianvink opened this issue 4 years ago • 3 comments

This is a really helpful tool, thank you.

I use Kendo to handle date pickers and Kendo expects a Date() object for FormControl values:

this.mainForm = this.fb.group({
  searchEndDate: [new Date(), Validators.required],
});

With the above, I get a Date() that Kendo consumes.

When I connect the Forms Manager,

 this.formsManager.upsert(this.formManagerKey, this.mainForm, {
   persistState: true
  });

Now 'searchEndDate' is a string

When I add the forms Manager, the date gets converted to a string. Is there a way to get the Forms Manager to maintain the type of the date as a Date()?

ianvink avatar Feb 08 '21 21:02 ianvink

No. You can't save a Date in localstorage.

NetanelBasal avatar Feb 09 '21 06:02 NetanelBasal

Hi,

Is there a way to add a custom deserializer JSON.parse() ? in there I can add a Revive function to convert the date string to a date?

This is such a wonderful project you have made, thank you for your kind efforts and work on it.

Ian

ianvink avatar Feb 09 '21 16:02 ianvink

You're welcome to submit a PR.

NetanelBasal avatar Feb 10 '21 06:02 NetanelBasal