Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
99 changes: 65 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
angular.module('isolateForm', []).directive('isolateForm', [function () {
return {
restrict: 'A',
require: '?form',
link: function (scope, elm, attrs, ctrl) {
if (!ctrl) {
return;
}

// Do a copy of the controller
var ctrlCopy = {};
angular.copy(ctrl, ctrlCopy);

// Get the parent of the form
var parent = elm.parent().controller('form');
// Remove parent link to the controller
parent.$removeControl(ctrl);

// Replace form controller with a "isolated form"
var isolatedFormCtrl = {
$setValidity: function (validationToken, isValid, control) {
ctrlCopy.$setValidity(validationToken, isValid, control);
parent.$setValidity(validationToken, true, ctrl);
},
$setDirty: function () {
elm.removeClass('ng-pristine').addClass('ng-dirty');
ctrl.$dirty = true;
ctrl.$pristine = false;
},
};
angular.extend(ctrl, isolatedFormCtrl);
}
};
}]);
// Uses Node, AMD or browser globals to create a module.

// If you want something that will work in other stricter CommonJS environments,
// or if you need to create a circular dependency, see commonJsStrict.js

// Defines a module "returnExports" that depends another module called "b".
// Note that the name of the module is implied by the file name. It is best
// if the file name and the exported global have matching names.

// If the 'b' module also uses this type of boilerplate, then
// in the browser, it will create a global .b that is used below.

// If you do not want to support the browser global path, then you
// can remove the `root` use and the passing `this` as the first arg to
// the top function.

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['angular'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('angular'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.angular);
}
}(typeof self !== 'undefined' ? self : this, function(angular) {
return angular.module('isolateForm', []).directive('isolateForm', [function() {
return {
restrict: 'A',
require: '?form',
link: function(scope, elm, attrs, ctrl) {
if (!ctrl) {
return;
}

// Do a copy of the controller
var ctrlCopy = {};
angular.copy(ctrl, ctrlCopy);

// Get the parent of the form
var parent = elm.parent().controller('form');
// Remove parent link to the controller
parent.$removeControl(ctrl);

// Replace form controller with a "isolated form"
var isolatedFormCtrl = {
$setValidity: function(validationToken, isValid, control) {
ctrlCopy.$setValidity(validationToken, isValid, control);
parent.$setValidity(validationToken, true, ctrl);
},
$setDirty: function() {
elm.removeClass('ng-pristine').addClass('ng-dirty');
ctrl.$dirty = true;
ctrl.$pristine = false;
}
};
angular.extend(ctrl, isolatedFormCtrl);
}
};
}]).name;
}));
15 changes: 2 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "isolate-form",
"description": "An Angular directive for nested forms that prevents $invalid from propagating",
"version": "1.0.6",
"version": "1.0.8",
"author": "91K00",
"bugs": {
"url": "https://github.com/nmutalik/isolate-form/issues",
Expand All @@ -20,8 +20,6 @@
"pre-git": "^0.6.2"
},
"engines": {
"node": "0.12.7",
"npm": "2.11.3"
},
"homepage": "https://github.com/nmutalik/isolate-form.git",
"keywords": [
Expand All @@ -40,14 +38,5 @@
"scripts": {
"nice": "grunty grunt-nice-package nice-package",
"test": "node-qunit *.js"
},
"pre-commit": [
"npm version"
],
"post-commit": "git status",
"pre-push": [
"rm -rf node_modules",
"npm install"
],
"post-merge": "npm install"
}
}
Loading