diff --git a/packages/oui-checkbox/src/checkbox.component.js b/packages/oui-checkbox/src/checkbox.component.js index 3663b59a..9e789c78 100644 --- a/packages/oui-checkbox/src/checkbox.component.js +++ b/packages/oui-checkbox/src/checkbox.component.js @@ -4,6 +4,9 @@ import template from "./checkbox.html"; export default { template, controller, + require: { + form: "?^^form" + }, bindings: { model: "=?", id: "@?", diff --git a/packages/oui-checkbox/src/checkbox.controller.js b/packages/oui-checkbox/src/checkbox.controller.js index bdf5101e..0e9658d7 100644 --- a/packages/oui-checkbox/src/checkbox.controller.js +++ b/packages/oui-checkbox/src/checkbox.controller.js @@ -17,7 +17,6 @@ export default class { // So we use $timeout to force the $apply this.$timeout(() => this.$element - .addClass("oui-checkbox") .removeAttr("id") .removeAttr("name") ); @@ -38,6 +37,13 @@ export default class { addDefaultParameter(this, "id", `ouiCheckbox${this.$scope.$id}`); } + hasError () { + if (!this.form || !this.form[this.name]) { + return false; + } + return (!this.form[this.name].$dirty || this.form.$submitted) && !this.focused && this.form[this.name].$invalid; + } + _updateIndeterminateState (model) { this.checkboxElement.prop("indeterminate", model === null); } diff --git a/packages/oui-checkbox/src/checkbox.html b/packages/oui-checkbox/src/checkbox.html index fc1249ef..4caca23f 100644 --- a/packages/oui-checkbox/src/checkbox.html +++ b/packages/oui-checkbox/src/checkbox.html @@ -1,28 +1,33 @@ - -