this is how validations are done in all JS servces. Please check CommunityService for instance.