So what I did, I went ahead and gave the field a custom template as follows:
formlyConfigProvider.setWrapper({ name: 'inputWrapper', template: '<div ng-class="to.changeColor==\'red\'? \'redBorder\' : \'otherBorder\'"><formly-transclude></formly-transclude>{{to.keyVal}}</div>' });
Form elements are defined through a layout format, allowing each element to be individually addressed.
vm.schema={ "schema": { "coolValue" : [{ "key": "coolValue", "type": "input", "wrapper": ['inputWrapper'], "templateOptions": { "type" : "text", "label": 'Cool Value', "keyVal":"", "changeColor":"green" } }] } };
Finally, the onSubmit function
function onSubmit() { //Do whatever you want here //Let say your server returns an error "iNVALID Credentials" var response={ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization", } ], "code": 401, "message": "Invalid Credentials" } }; vm.schema.schema.coolValue[0].templateOptions.changeColor="red"; vm.schema.schema.coolValue[0].templateOptions.keyVal=response.error.message; } });
You can send any error message or response from the server here.
CSS contains a class that adds a red border to a field. You can disable this. Feel free to ping if you need anything in this area.
Here is a demo
source share