FormStore Instance 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()

Loads data from server (using server.get) unless a refresh was performed within the last minRefreshInterval. 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).

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

This method is mostly for internal use by refresh() - it copied the data in model.getSavedData() to model.data and sets up a dataErrors observable that mirrors the structure of data but with all null values.

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.

results matching ""

    No results matching ""