From 5a39444daa7ec650d48ce43b775d476f74515219 Mon Sep 17 00:00:00 2001 From: "jean-christophe.alleman" Date: Mon, 12 Nov 2018 14:21:19 +0100 Subject: [PATCH 1/2] feat(oui-checkbox): add error class when checkbox is in error --- .../oui-checkbox/src/checkbox.component.js | 3 + .../oui-checkbox/src/checkbox.controller.js | 8 ++- packages/oui-checkbox/src/checkbox.html | 57 ++++++++++--------- 3 files changed, 40 insertions(+), 28 deletions(-) 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..8506566e 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) { + return false; + } + return this.form.$submitted && 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..f2e33dd8 100644 --- a/packages/oui-checkbox/src/checkbox.html +++ b/packages/oui-checkbox/src/checkbox.html @@ -1,28 +1,31 @@ - -