ForgeTotal.js 5
en

Total.js 5

Validate the query string in an action

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

Like input for the body and params for the path, query describes the query string. The framework validates it and converts the values (the page number below arrives as a real number); an invalid query answers with a validation error before your code runs.

definitions/search.js
NEWACTION('Search/exec', {
	name: 'Search',
	query: 'q:String, page:Number, *sort:Lowercase',
	action: function($) {
		$.callback({ q: $.query.q || '', page: $.query.page || 1, sort: $.query.sort });
	}
});
controllers/search.js
exports.install = function() {
	ROUTE('GET /search/ --> *Search/exec');
};