ngneat / forms-manager

🦄 The Foundation for Proper Form Management in Angular
https://www.netbasal.com
MIT License
518 stars 29 forks source link

Add parse and serializer options for persistState #23

Open ianvink opened 3 years ago

ianvink commented 3 years ago

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()?

NetanelBasal commented 3 years ago

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

ianvink commented 3 years ago

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

NetanelBasal commented 3 years ago

You're welcome to submit a PR.