🌊
jsf
  • About KalmiaJSF
  • Setup
  • Architecture
  • Contributing
  • Changelog
  • Guides
    • Cheat Sheet
  • Examples
    • Demo example
    • Basic examples
    • Kitchen Sink example
    • Charts example
  • Schema
    • Intro to Schema
    • Prop types
      • String
      • Boolean
      • Number & Integer
      • Object
      • Array
      • Date
      • Id
      • Null
      • Ref
      • Binary
    • Prop options
      • Disabling property
      • On prop init actions
      • Persist
      • On value change
      • On user value change
    • Handlers
      • Color picker
    • Creating custom handler
      • Working with arrays
    • Value provider
  • Validation
    • Custom validation
    • Eval
  • LAYOUT
    • Intro to Layout
    • Layout options
      • Show & hide
      • On click action
  • INTERFACES
    • Value Options
  • Form
    • Form data
  • OTHER
    • Events
    • Lifecycle hooks
    • Notifications support
  • PAGES & COMPONENTS
    • Page
    • Component
  • THEMING
    • Creating new theme variant
  • BUILDER
    • Shortcuts
  • Help
    • FAQ
Powered by GitBook
On this page
  • Example
  • Array edge cases

Was this helpful?

Export as PDF
  1. Schema
  2. Prop options

Persist

With persist keyword, you can make changes on form persistent. This can be useful when you want to preserve prop values on browser refreshes, share filled form as link, share some filter settings etc.

Keyword

Type

type

'query', 'localStorage'

What type of storage to use.

key

string (optional)

Under what key to store value. If not set prop path is used.

For example key: 'abc' will be set in query as ?abc=123

loadMap

$eval (optional)

Mapper when retrieving the data from the persistence.

storeMap

$eval (optional)

Mapper when storing the data to persistence.

Example

When prop value is changed it will be also saved into URL under query key my-key. When the form is opened again URL query will be checked if the value can be retrieved.

{
    type: 'string',
    persist: {
        type: 'query',
        key: 'my-key'
    }
}

Persist has priority before default and advancedDefault.

Array edge cases

You can not use persists on array prop children, since all children will have the same key. Exception is a static array where you can manually set different keys. But you can easily set persist on array level or parent object.

Wrong

All array items will have same key, this is probably not what you need.

{
    type: 'array',
    items: {
        type: 'string',
        persist: { type: 'localSTorage' }
    }
}

Correct

If you need to make array persistent, set persist keyword on array level.

{
    type: 'array',
    persist: { type: 'localSTorage' },
    items: {
        type: 'string'
    }
}

Correct

If you have static array, you can set your own keys for items in that case storage is stable.

{
    type: 'array',
    items: [
        {
            type: 'string', 
            persist: { type: 'localSTorage', key: 'my-1' },
        },
        {
            type: 'string', 
            persist: { type: 'localSTorage', key: 'my-2' },
        }
    ]
}
PreviousOn prop init actionsNextOn value change

Last updated 4 years ago

Was this helpful?