Methods

getSavedData()

Returns the last saved (or server-provided) set of data. In an afterSave callback it already includes merged updates that were not in error. Since model.data can contain in-progress and invalid data, this can sometimes be useful to get 'known-good' data.

getValue(name, validated = false, skipPropertyBeingEdited = false)

Returns the value of a field/property, optionally returning the last saved value for not validated/in progress fields. It is NOT necessary to use this method just to obtain the value of a given property. Simply use model.data[name]. But with validated = true, this method will return model.data[name] only if that property is not in error and if it is, it will effectively return model.getSavedData()[name]. Same for skipPropertyBeingEdited, if true, if the requested field is in progress of being edited, it'll return its previously saved value instead. You can use this method in the beforeSave callback if you need to include additional data for the server that hasn't changed and you need 'known good' values.

isSame(value1, value2)

Returns true if the two provided values can be considered the same (and hence unchanged). By default, this function uses == instead of === (so that "1" and 1 are considered same) and handles different date objects with the same date value. Currently all falsy values (i.e. undefined, null, false, 0, empty string) are considered the same. This may change in future releases so that 0 and false can be differentiated from undefined/null. You can override this instance method with your own function and it will be used by FormStore's change tracking mechanism.

refresh({ allowIfMustCreate = false, ignoreMinRefreshInterval = false })

Loads data from server (using server.get) unless a refresh was performed within the last minRefreshInterval (in v2.2+, you can override this by providing the ignoreMinRefreshInterval: true option). If there are pending (and ready to save) changes, refresh() triggers save() instead and 'resets the clock' on minRefreshInterval as if it performed a refresh.

For a store with a non-null idProperty, if the value of that property is falsy (i.e. model hasn't been created on the server yet), refresh() calls server.get only the very first time refresh() is called (and if data was provided to FormStore constructor, then never). In v2.2+, you can override this by providing the allowIfMustCreate: true option.

It returns a Promise which resolves (when server responds with data and the model is updated) with true if refresh was actually performed, and false if it was skipped.

This method is typically set up to run whenever the form is (re-)loaded (componentWill/DidMount and componentWillUpdate) or the app resumes running, etc.

reset(data)

This method is mostly for internal use by the constructor and refresh() - it copies the data in model.getSavedData() (i.e. dataServer) to model.data and sets up a dataErrors observable that mirrors the structure of data but with all null values. In v1.4+, it also 'resets the clock' on minRefreshInterval, allowing a refresh() even if one was just performed. In v2.3+, if data object is provided to reset(), dataServer will be set to it and store.isReady will be set to true, same as when providing data object to the constructor.

save({ allowCreate = false, saveAll = false, skipPropertyBeingEdited = false, keepServerError = false } = {})

startEditing(name)

Marks field/data property as edit-in-progress and therefore it should not be autosaved. This method is to be called on field focus.

stopEditing()

Unmarks previously marked property. This method is to be called on field blur. Any field name parameter is ignored.

dispose()

(NEW in v1.1) Call this method to stop all auto saves and data change observation. This will allow this instance to get memory-garbage-collected if you stop referencing it.

configAutoSave(autoSaveInterval, autoSaveOptions)

(NEW in v1.3) This method can be used to update the autoSaveInterval and autoSaveOptions settings originally provided to the constructor. If autoSaveInterval is zero, auto-save will be disabled, otherwise it will be enabled.

Last updated