From fc58dc4bd93f2905227dac199c73470fbb3aac67 Mon Sep 17 00:00:00 2001 From: Roi Kingon Date: Thu, 1 Oct 2015 17:08:35 -0700 Subject: [PATCH 1/4] update to fix $dirty bug --- angular-redactor.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/angular-redactor.js b/angular-redactor.js index 5a106ae..6f95032 100644 --- a/angular-redactor.js +++ b/angular-redactor.js @@ -25,9 +25,7 @@ var updateModel = function updateModel(value) { // $timeout to avoid $digest collision $timeout(function() { - scope.$apply(function() { - ngModel.$setViewValue(value); - }); + ngModel.$setViewValue(value); }); }, options = { @@ -53,6 +51,7 @@ $timeout(function() { editor = element.redactor(options); ngModel.$render(); + ngModel.$setPristine(); element.on('remove',function(){ element.off('remove'); element.redactor('core.destroy'); From 3ff275fa9c57074191b5591896931e4acdfe2870 Mon Sep 17 00:00:00 2001 From: Roi Kingon Date: Thu, 1 Oct 2015 17:09:38 -0700 Subject: [PATCH 2/4] update to fix $dirty bug --- angular-redactor-9.x.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/angular-redactor-9.x.js b/angular-redactor-9.x.js index fe6e0c3..2d77ac3 100644 --- a/angular-redactor-9.x.js +++ b/angular-redactor-9.x.js @@ -25,9 +25,7 @@ var updateModel = function updateModel(value) { // $timeout to avoid $digest collision $timeout(function() { - scope.$apply(function() { - ngModel.$setViewValue(value); - }); + ngModel.$setViewValue(value); }); }, options = { @@ -52,6 +50,7 @@ $timeout(function() { editor = element.redactor(options); ngModel.$render(); + ngModel.$setPristine(); }); ngModel.$render = function() { From e1d634b1be6a0ad75dab12d062ef4b09dd1a1e2b Mon Sep 17 00:00:00 2001 From: Roi Kingon Date: Thu, 1 Oct 2015 17:45:35 -0700 Subject: [PATCH 3/4] allows the form to be pristine as well --- angular-redactor.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/angular-redactor.js b/angular-redactor.js index 6f95032..ddd7a3c 100644 --- a/angular-redactor.js +++ b/angular-redactor.js @@ -21,11 +21,18 @@ // Expose scope var with loaded state of Redactor scope.redactorLoaded = false; - + + var assignPristine = true; var updateModel = function updateModel(value) { // $timeout to avoid $digest collision $timeout(function() { - ngModel.$setViewValue(value); + if(value) { + ngModel.$setViewValue(value); + if(assignPristine) { + ngModel.$setPristine(); + assignPristine = false; + } + } }); }, options = { @@ -51,7 +58,6 @@ $timeout(function() { editor = element.redactor(options); ngModel.$render(); - ngModel.$setPristine(); element.on('remove',function(){ element.off('remove'); element.redactor('core.destroy'); @@ -71,4 +77,3 @@ }; }]); })(); - From f24ec549858ce4ac3e52d8419b356faee435ad4c Mon Sep 17 00:00:00 2001 From: Roi Kingon Date: Thu, 1 Oct 2015 17:47:13 -0700 Subject: [PATCH 4/4] allow form to be $pristine as well --- angular-redactor-9.x.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/angular-redactor-9.x.js b/angular-redactor-9.x.js index 2d77ac3..9a90a0d 100644 --- a/angular-redactor-9.x.js +++ b/angular-redactor-9.x.js @@ -21,11 +21,18 @@ // Expose scope var with loaded state of Redactor scope.redactorLoaded = false; - + + var assignPristine = true; var updateModel = function updateModel(value) { // $timeout to avoid $digest collision $timeout(function() { - ngModel.$setViewValue(value); + if(value) { + ngModel.$setViewValue(value); + if(assignPristine) { + ngModel.$setPristine(); + assignPristine = false; + } + } }); }, options = { @@ -50,7 +57,6 @@ $timeout(function() { editor = element.redactor(options); ngModel.$render(); - ngModel.$setPristine(); }); ngModel.$render = function() {