ForgeTotal.js 5
en

Total.js 5

Pick the right input type for an action

Total.js 5 · total5@0.0.19 actionsvalidationtypes Executed against Total.js 5

The input of an action is a list of name:Type fields separated by commas. A * before the name makes the field required. Besides validating, many types convert the value, so the action receives clean data:

TypeResult
String, Number, Boolean, Date, Object, Arraythe basic types (strings are trimmed, numbers and dates are parsed)
Email, Phone, URL, UID, GUID, Base64, Color, Zipvalidated formats
Lowercase, Uppercase, Capitalize, Capitalize2, Nametext converted to that style: Capitalize capitalizes every word, Capitalize2 only the first letter of the text and lowercases the rest
definitions/types.js
NEWACTION('Types/exec', {
	name: 'Typed input',
	input: '*email:Email, age:Number, active:Boolean, nick:Lowercase, code:Uppercase, title:Capitalize, sentence:Capitalize2, site:URL',
	action: function($, model) {
		$.callback(model);
	}
});
controllers/types.js
exports.install = function() {
	ROUTE('POST /types/ --> *Types/exec');
};