partial.js logo
Latest version
v1.3.1 (RC2)

Builders.ErrorBuilder


Error builder is helpful for model error handling.


var builders = require('partial.js/builders');
var builder = new builders.ErrorBuilder();

Methods


builder.add(name, [errorMessage])builder.clear()builder.hasError([name])builder.json()builder.read(name)builder.remove(name)builder.replace(search, newValue)new ErrorBuilder([onResource])
builder.add(name, [errorMessage]);
return ErrorBuilder;

Add an error to ErrorBuilder. You can add other ErrorBuilder - builder.add(new builders.ErrorBuilder()).

builder.add('Name'); // load: builder.onResource('Name');
builder.add('Name', '@NameMinimum'); // load: builder.onResource('NameMinimum');
builder.add('Name', 'You must enter your name.');

builder.clear();
return ErrorBuilder;

Clear error collections.

builder.hasError([name]);
return Boolean;

Has collection an error? If name is not defined then ErrorBuilder check it if collection contains any error.

builder.json();
return ErrorBuilder;

Serialize ErrorBuilder into the JSON. Collection is serialized as array: [{ name: 'Property', error: 'Error message.'}].
Framework supports:

controller.json(ErrorBuilder);

builder.read(name);Default: null
return String;

Read error message

builder.remove(name);
return ErrorBuilder;

Remove error from ErrorBuilder.

builder.replace(search, newValue);
return ErrorBuilder;

Replace error message.

new ErrorBuilder([onResource]);
return ErrorBuilder;

Create an instance.