diff --git a/README.md b/README.md
index 15673ce8f..8a658b850 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,31 @@
+# Alpaca - Modified version - New features added
+
+- A Copy function for arrays. A new icon is added to the toolbar that copies
+ the current element.
+
+- New dependency system. Dependencies are specified as part of the options json, using the field "x\_dependencies". x\_dependencies is an array of objects, with the following fields:
+ - "field" : path to field that is to be checked (no leading slash). Use "[]" to indicate all elements of an array.
+ - "values": array of values against which _field_ is checked.
+ - "enables": array of relative paths to fields that are to be enabled when _field_ is equal to one of the values. The path root is the parent of the element indicated by _field_. So, dependencies can refer to siblings of the _field_ element, or to elements deeper in the tree. "[]" can again be used to specify all elements of an array.
+
+ Example.
+ ```
+ {
+ "options": {
+ "x_dependencies": [
+ {
+ "field": "questions[]/type",
+ "values": ["likert","vas"],
+ "enables": [ "desc/nld_nld/anchors", "range"]
+ }
+ ]
+ }
+ }
+ ```
+ This checks if the _type_ field of each element of the _questions_ array is equal to either of the two given strings. If true, the _range_ field in the same element and the *desc.nld_nld.anchors* subfields are enabled. If false, they are disabled (hidden).
+
# Alpaca - JSON Forms for jQuery and Bootstrap
Alpaca provides the easiest and fastest way to generate interactive forms for the web and mobile devices.
diff --git a/gulpfile.js b/gulpfile.js
index 8e260ff0a..939ee3c48 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -55,6 +55,7 @@ var paths = {
"src/js/ControlField.js",
"src/js/ContainerField.js",
"src/js/Form.js",
+ "src/js/PathBasedDependencies.js",
// cache implementations
"src/js/cache/memory.js",
diff --git a/src/js/Alpaca.js b/src/js/Alpaca.js
index ad2c688ae..7f58b3cec 100644
--- a/src/js/Alpaca.js
+++ b/src/js/Alpaca.js
@@ -394,6 +394,8 @@
_resetInitValidationError(field);
}
+ // Dependency management is performed as a postrender call
+ Alpaca.PathBasedDependencies.postRenderCallback(field);
if (renderedCallback)
{
renderedCallback(field);
diff --git a/src/js/PathBasedDependencies.js b/src/js/PathBasedDependencies.js
new file mode 100644
index 000000000..1949b46e0
--- /dev/null
+++ b/src/js/PathBasedDependencies.js
@@ -0,0 +1,140 @@
+(function() {
+Alpaca.PathBasedDependencies = (function() {
+
+ //var registry = {};
+
+ return {
+
+ postRenderCallback: function(control) {
+ if (!control.options.x_dependencies) return;
+ var deps = control.options.x_dependencies;
+ control.on("change", function() {
+ var deps = this.options.x_dependencies;
+ Alpaca.PathBasedDependencies.updateDeps(deps,this,
+ Alpaca.PathBasedDependencies.processDepLeaf);
+ });
+ Alpaca.PathBasedDependencies.doRecursive(control, function(current) {
+ current.on("add",function() {
+ //console.log("########ADD EVENT");
+ Alpaca.PathBasedDependencies.updateDeps(deps,control,
+ Alpaca.PathBasedDependencies.processDepLeaf);
+ });
+ current.on("move",function() {
+ //console.log("########ADD EVENT");
+ Alpaca.PathBasedDependencies.updateDeps(deps,control,
+ Alpaca.PathBasedDependencies.processDepLeaf);
+ });
+ });
+ // now, run it once to initialize
+ Alpaca.PathBasedDependencies.updateDeps(deps,control,
+ Alpaca.PathBasedDependencies.processDepLeaf);
+ },
+
+ // call callback(element) on current and all of its children
+ doRecursive: function(current,callback) {
+ callback(current);
+ if (!current.children) return;
+ for (var i=0; i check dependency
+ if (typeof current == "undefined") return;
+ if (!current) return;
+ callback(dep,current);
+ return;
+ }
+ var name = pathArray.shift();
+ var isArray=false;
+ var z = name.indexOf("[]");
+ if (z >= 0) {
+ name = name.substring(0,z);
+ isArray=true;
+ }
+ //console.log(name+"#"+isArray+"$");
+ current = current.childrenByPropertyId[name];
+ if (!isArray) {
+ Alpaca.PathBasedDependencies.processDep(dep,pathArray,current,callback);
+ } else {
+ //console.log("array size "+current.children.length);
+ for (var j=0; j disable
+ for (var j=0; j