ForgeDocumentation
en

Documentation

Input types of NEWACTION

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

A definition is a list of name:Type separated by commas, for example *email:Email, age:Number. A * before the name makes the field required. The same format is used by input (the body), params, query and output. The type converts the value: the action receives the converted value, not the text that was sent.

The names of the types are not case sensitive. Every type below was checked by sending the value in the second column.

TypeValue sentValue receivedNotes
String hello helloText; leading and trailing spaces are removed.
Text text text Text kept exactly as it was sent.
Email A@B.CZ a@b.czA valid email address, in lowercase; anything else is rejected.
Phone+421 900 123 456+421900123456A phone number; spaces are removed.
URLhttps://totaljs.com/xhttps://totaljs.com/xA valid URL; anything else is rejected.
Namejohn smithJohn SmithCapitalizes every word.
Capitalizehello big worldHello Big WorldCapitalizes every word.
Capitalize2HELLO big WORLDHello big worldCapitalizes the first letter only and lowercases the rest.
LowercaseABCabcLowercase.
UppercaseabcABCUppercase.
SearchŽluťoučký Kůňzlutoucki kunLowercase without accents, for searching.
SafeStringplain textplain textText; a value with HTML tags such as <b> is rejected.
Color#FF0000#FF0000schema-enums-and-formats
Base64SGVsbG8=SGVsbG8=schema-enums-and-formats
Zip8110181101schema-enums-and-formats
Iconti ti-hometi ti-homeschema-enums-and-formats
Number12.512.5A number; the text is converted.
Float3.143.14A number; the text is converted.
Decimal2.52.5A number; the text is converted.
Booleantruetruetrue or false; the text true is converted.
Date2026-01-052026-01-05T00:00:00.000ZA date. In JSON it is sent as an ISO text.

Other forms:

FormExampleNotes
[String], [Number]ze_arr:[String]An array of that type: every item is converted.
{ x:Number, y:String }zg_obj:{ x:Number, y:String }A nested object, validated with its own fields.
String(5)zd_max:String(5)A text of at most 5 characters; a longer text is rejected.

A value that does not fit the type is rejected with status 400 and the name of the field in the error. These values were rejected in the checks: SafeString with <b>x</b>, String(5) with ten characters, a UID with abc, and a GUID with not-guid. The boundary recipe verifies Int, SmallInt, TinyInt, Number2: numeric-schema-boundaries. In this version Int does not truncate: 7.9 stays 7.9.

UID and GUID accept the values that UID() and GUID() create.

definitions/types.js
NEWACTION('Types/all', {
	name: 'Every type',
	input: 'a_string:String, b_text:Text, c_email:Email, d_phone:Phone, e_url:URL, f_name:Name, g_capitalize:Capitalize, h_capitalize2:Capitalize2, i_lowercase:Lowercase, j_uppercase:Uppercase, k_search:Search, l_safestring:SafeString, m_color:Color, n_base64:Base64, o_zip:Zip, p_icon:Icon, q_number:Number, r_float:Float, s_decimal:Decimal, t_boolean:Boolean, u_date:Date, ze_arr:[String], zf_nums:[Number], zg_obj:{ x:Number, y:String }, zd_max:String(5)',
	action: function($, model) {
		$.callback(model);
	}
});

NEWACTION('Types/ids', {
	name: 'UID and GUID',
	input: '*id:UID, *key:GUID',
	action: function($, model) {
		$.callback(model);
	}
});
controllers/types.js
exports.install = function() {
	ROUTE('POST /types/ @json --> *Types/all');
	ROUTE('POST /ids/ @json --> *Types/ids');
	ROUTE('GET /newids/', ids);
};

function ids($) {
	$.json({ id: UID(), key: GUID() });
}