Skip to content

Commit

Permalink
Replace checkchange with form-changed
Browse files Browse the repository at this point in the history
Instead of checking individual inputs for change check whole form for changes
  • Loading branch information
ZitaNemeckova committed Apr 20, 2017
1 parent 6d5faea commit bd9d2d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/assets/javascripts/directives/form_changed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ManageIQ.angular.app.directive('formChanged', function() {
return {
require: "form",
link: function(scope, elem, attr, ctrl) {
var model = function() {
return scope.$eval(ctrl.model || scope.model);
};
var modelCopy = function() {
return scope.$eval(ctrl.modelCopy || "modelCopy");
};
scope.$watchCollection(ctrl.model || scope.model, function() {
if (angular.equals(model(), modelCopy())) {
ctrl.$setPristine();
}
});
},
};
});

2 changes: 1 addition & 1 deletion app/views/ansible_credential/_credential_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'miq-form' => true,
'model' => 'vm.credentialModel',
'model-copy' => 'vm.modelCopy',
'form-changed' => true,
'novalidate' => true}
= render :partial => "layouts/flash_msg"
.form-group{"ng-class" => "{'has-error': angularForm.name.$invalid}"}
Expand All @@ -19,7 +20,6 @@
'ng-model' => "vm.credentialModel.name",
:maxlength => MAX_NAME_LEN,
:required => true,
:checkchange => true,
"auto-focus" => ""}
%span.help-block{"ng-show" => "angularForm.name.$error.required"}
= _("Required")
Expand Down

0 comments on commit bd9d2d4

Please sign in to comment.