Anonymous avatar Anonymous committed b61a287

Added javascript code which tries to evalute values based on a given
expression.

Comments (0)

Files changed (1)

formbar/templates/formbar.js

 $('.formbar-datepicker').datepicker({
     format: 'yyyy-mm-dd'
 });
+
 /*
 * Set hidden form field "formbar-page" to the value of the currently
 * selected page. This value will be used to set the currently selected
         },
         function(data, status) {});
 });
+
+/*
+ * Evaluate when values in the form changes 
+*/
+$('div.formbar-form form input').change(function() {
+    var fieldsToEvaluate = $('.formbar-evaluate');
+    for (var i = fieldsToEvaluate.length - 1; i >= 0; i--){
+        var field = fieldsToEvaluate[i];
+        var expr = field['attributes'][0].value;
+        var id = field['attributes'][1].value;
+        // Now get all $fieldnames
+        var tokens = expr.split(" ");
+        var eval_expr = "";
+        for (var j = tokens.length - 1; j >= 0; j--){
+            var tfield = null
+            var value = null
+            if (tokens[j].contains("$")) {
+                tfield = tokens[j].replace('$', '');
+                value = $('input[name='+tfield+']').val();
+                console.log(tokens[j].replace('$', ''));
+                eval_expr += value;
+            } else {
+                eval_expr += tokens[j];
+            }
+        };
+        try {
+            var eval_value = eval(eval_expr);
+            $('#'+id).text(eval_value);
+        } catch (e) {
+            console.log(e);
+            $('#'+id).text("");
+        }
+    };
+});
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.