rackem
Well-Known Member
I had some custom Javascript that was working in F3 but now it is not after updating to F3.1. I see that some changes were made
http://fabrikar.com/forums/index.php?wiki/upgrading-from-3-0-to-3-1/
So I am trying to follow the instructions here
http://fabrikar.com/forums/index.php?wiki/adding-custom-javascript/
I got my code working on a new record but I get an error when editing an existing record. Basically, all my code does is insert the repeat group number into a field when a repeat group is added.
Here is my code. Note my custom code is just the part between the *********:
The error occurs in the line
On new records, Fabrik.blocks['form_24'] is defined.
However when editing a record, I need Fabrik.blocks['form_24_X'] where X is the record id. How do I get that? It seems that the script given in the instructions takes care of this somehow but I am missing how to get it working.
I also discovered that the wiki link is broken on this page
http://fabrikar.com/forums/index.php?wiki/form-javascript/
that used to go to here
http://fabrikar.com/forums/index.php?wiki/Fabrik_3_form_javascript/
http://fabrikar.com/forums/index.php?wiki/upgrading-from-3-0-to-3-1/
So I am trying to follow the instructions here
http://fabrikar.com/forums/index.php?wiki/adding-custom-javascript/
I got my code working on a new record but I get an error when editing an existing record. Basically, all my code does is insert the repeat group number into a field when a repeat group is added.
Here is my code. Note my custom code is just the part between the *********:
Code:
// Ensure that Fabrik is loaded
// Make sure to match the form_X matches (2 places!)
requirejs(['fab/fabrik'], function () {
// The block you want to use
var blockRef = 'form_24';
// Should we use an exact match for the blockRef?
var exact = false;
// Bool to ensure ini() is only called once
var setup = false;
// Add an event to watch for when blocks are added.
Fabrik.addEvent('fabrik.block.added', function () {
if (setup) {
return;
}
var block = Fabrik.getBlock(blockRef, exact);
// If we find our form, we should call the ini() method
if (block !== false) {
setup = true;
ini(block);
}
});
// **************************************************************
// Put your code here
// Inserts the group number as the default value for the place field
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event, g_id, r_count){
var places = $('group' + g_id).getElements('input[name *= mps_pub_results___place]');
var new_id = places[r_count].id;
Fabrik.blocks['form_24'].formElements.get(new_id).update(r_count + 1);
});
// **************************************************************
var ini = function (block) {
console.log('ini form_24.js', block);
}
});
The error occurs in the line
Code:
Fabrik.blocks['form_24'].formElements.get(new_id).update(r_count + 1);
On new records, Fabrik.blocks['form_24'] is defined.
However when editing a record, I need Fabrik.blocks['form_24_X'] where X is the record id. How do I get that? It seems that the script given in the instructions takes care of this somehow but I am missing how to get it working.
I also discovered that the wiki link is broken on this page
http://fabrikar.com/forums/index.php?wiki/form-javascript/
that used to go to here
http://fabrikar.com/forums/index.php?wiki/Fabrik_3_form_javascript/