1.0.1 • Published 9 years ago
hof-behaviour-session v1.0.1
#hof-behaviour-session
HOF Behaviour for reading and writing to the session
##Usage
###With mixwith.js
const mix = require('mixwith').mix;
const Session = require('hof-behaviour-session');
const BaseController = require('hof-form-controller');
class MyController extends mix(BaseController).with(Session) {
...
}MyController now extends hof-form-controller and has hof-behaviour-session functionality mixed in.
##Functionality
This mixin extends hof-form-controller by persisting the form data to the sessionModel - assuming the session-model middleware has been applied.
The following form controller methods are used:
getValues(req, res, cb)- calls callback withnulland a map of all items in thesessionModel, extended witherrorValues- to persist entered values on current step if validation failssaveValues(req, res, cb)- Called on success. Sets all step fields inreq.form.valuesto the sessionModel, unsetserrorValues.getErrors(req)- returns all errors for fields on the current step (req.form.options.fields), excluding redirects. Set toreq.form.errorsinhof-form-controller.setErrors(err, req)- called on validation error(s). Sets the current step field values aserrorValuesin sessionModel to be used ingetValues. Setserrorsto sessionModel - a map offield-name: errorto be used ingetErrors.locals(req, res)- Extends the result ofsuper.localswithbaseUrl(req.baseUrl) andnextPage(the result ofthis.getNextStep(req, res)).missingPrereqHandler(req, res)- Error handler called when aMISSING_PREREQerror is thrown from the check-progress middleware. This occurs if a step is visited out of sequence. This error handler causes the user to be redirected to the last completed step, or the first step if none have been completed.errorHandler(err, req, res, next)- checks iferr.codeisMISSING_PREREQ, if so callsmissingPrereqHandler, if not callssuperto hand over to parent error handler.