Skip to content

Commit

Permalink
Allow to pass in boolean to noDirtyCheck directive (#8638)
Browse files Browse the repository at this point in the history
* Adjust noDirtyCheck directive to accept a parameter to enable/disable dirty check

* Update dirty property

* Use Utilities.noop and add description

* Set default value from controller

* Check for truthly value

* Use Object.toBoolean

* Revert setting $pristine and $dirty for now

* Handle default values in dirty check attributes

* Add check on presence of disableDirtyCheck atribute

* Check for truthy value otherwise it should be default return false and work as no-dirty-check without value

* update test conditions for vamue of no-dirty-check and disable-dirty-check

* Remove whitespace

* update check

Co-authored-by: Kenn Jacobsen <[email protected]>
Co-authored-by: Michael <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2021
1 parent 20eda44 commit 7757c4d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
(function () {
'use strict';

function UmbCheckboxController($timeout, localizationService) {
function UmbCheckboxController($timeout, $attrs, localizationService) {

var vm = this;

Expand All @@ -50,7 +50,12 @@

function onInit() {
vm.inputId = vm.inputId || "umb-check_" + String.CreateGuid();

vm.disableDirtyCheck =
$attrs.hasOwnProperty("disableDirtyCheck") &&
vm.disableDirtyCheck !== '0' &&
vm.disableDirtyCheck !== 0 &&
vm.disableDirtyCheck !== 'false' &&
vm.disableDirtyCheck !== false;
vm.icon = vm.icon || vm.iconClass || null;

// If a labelKey is passed let's update the returned text if it's does not contain an opening square bracket [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(function () {
'use strict';

function UmbRadiobuttonController($timeout, localizationService) {
function UmbRadiobuttonController($timeout, $attrs, localizationService) {

var vm = this;

Expand All @@ -49,7 +49,12 @@

function onInit() {
vm.inputId = vm.inputId || "umb-radio_" + String.CreateGuid();

vm.disableDirtyCheck =
$attrs.hasOwnProperty("disableDirtyCheck") &&
vm.disableDirtyCheck !== '0' &&
vm.disableDirtyCheck !== 0 &&
vm.disableDirtyCheck !== 'false' &&
vm.disableDirtyCheck !== false;
vm.icon = vm.icon || vm.iconClass || null;

// If a labelKey is passed let's update the returned text if it's does not contain an opening square bracket [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ function noDirtyCheck() {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {

// if "no-dirty-check" attribute is explicitly falsy, then skip and use default behaviour. In all other cases we consider it truthy
var skipNoDirtyCheck = attrs.noDirtyCheck === '0' || attrs.noDirtyCheck === 0 || attrs.noDirtyCheck.toString().toLowerCase() === 'false';
if (skipNoDirtyCheck)
return;

var alwaysFalse = {
get: function () { return false; },
set: function () { }
};
get: function () { return false; },
set: function () { }
};

Object.defineProperty(ctrl, '$pristine', alwaysFalse);
Object.defineProperty(ctrl, '$dirty', alwaysFalse);

}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
<label class="checkbox umb-form-check umb-form-check--checkbox {{vm.cssClass}}" ng-class="{ 'umb-form-check--disabled': vm.disabled }">
<span class="umb-form-check__symbol">
<input ng-if="vm.disableDirtyCheck"
type="checkbox"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()"
no-dirty-check />

<input ng-if="!vm.disableDirtyCheck"
type="checkbox"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()"/>
<input type="checkbox"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()"
no-dirty-check="{{vm.disableDirtyCheck}}" />

<span class="umb-form-check__state" aria-hidden="true">
<span class="umb-form-check__check">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
<label class="radio umb-form-check umb-form-check--radiobutton {{vm.cssClass}}" ng-class="{ 'umb-form-check--disabled': vm.disabled }">
<span class="umb-form-check__symbol">
<input ng-if="vm.disableDirtyCheck"
type="radio"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()"
no-dirty-check />

<input ng-if="!vm.disableDirtyCheck"
type="radio"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()" />
<input type="radio"
id="{{vm.inputId}}"
name="{{vm.name}}"
value="{{vm.value}}"
class="umb-form-check__input"
val-server-field="{{vm.serverValidationField}}"
ng-model="vm.model"
ng-disabled="vm.disabled"
ng-required="vm.required"
ng-change="vm.change()"
no-dirty-check="{{vm.disableDirtyCheck}}" />

<span class="umb-form-check__state" aria-hidden="true">
<span class="umb-form-check__check"></span>
Expand Down

0 comments on commit 7757c4d

Please sign in to comment.