See the details here
Fabrik.addEvent(eventName, function(form){
// do your code here
});
// Your form reference
var formRef = 'form_2';
// The group you wish to repeat's ID
var groupId = 1;
// The number of times to repeat
var repeatNum = 3;
var form = Fabrik.blocks[formRef];
// Get the repeat group button
var btn = form.getElement('#group' + groupId + ' .addGroup');
if (typeOf(btn) !== 'null') {
// Create mock event
var e = new Event.Mock(btn, 'click');
// Duplicate group
for (var i = 1; i < repeatNum ; i ++) {
form.duplicateGroup(e);
}
}
Fabrik.addEvent('fabrik.form.submit.start', function(form, event, button) {
alert('aha! you really should not press that button');
form.result = false;
})
Fabrik.addEvent('fabrik.form.delete', function (form, rowid) {
return false;
});
// If you don't return false then the fabrik.form.submit event will be fired
// Alter formRef and endDate to match your form's id and the end Date element's full name:
var formRef = 'form_1';
var endDate = 'tablename___end_date';
var end = Fabrik.blocks[formRef].formElements.get(endDate);
var newDate = new Date(this.get('value'));
newDate.increment('hour', 2);
end.update(newDate);
// Alter the 1 & 2 to match you form ids.
var detailsRef = 'details_1';
var formRef = 'form_2';
Fabrik.addEvent('fabrik.form.Elements.added', function (block) {
// Ensure that both the form and details view have loaded
if (Object.getLength(Fabrik.blocks) === 2) {
// Copy the line below and alter for each element you want to update
copyFromDetails('userlist___name', 'tasks___username');
copyFromDetails('userlist___surname', 'tasks___surname');
}
});
function copyFromDetails(from, to) {
// Get the details view and Elements:
var fromElements = Fabrik.blocks[detailsRef].formElements;
// Get the form and its Elements
var toElements = Fabrik.blocks[formRef].formElements;
// Get details value
var fromValue = fromElements.get(from).get('value');
// Update form element with value.
taskElements.get(to).update(fromValue);
}
Fabrik.addEvent('fabrik.form.Elements.added', function () {
// All the elements have been loaded in Fabrik
var form = Fabrik.blocks.form_1; // Replace 1 with your form id
var elements = form.formElements;
var date1 = elements.get('tablename___date1');
var date2 = elements.get('tablename___date2');
var output = elements.get('tablename___output');
// A function to work out the date difference
var doDiff = function () {
// Create two JS date objects
var d1 = new Date.parse(date1.get('value'));
var d2 = new Date.parse(date2.get('value'));
// diff in miliseconds
var diff = d1 - d2;
var dayDiff = diff / (24 * 60 * 60 * 10 * 10 * 10);
// Update the output element with the number of days
output.update(dayDiff);
}
// Add events to the two dates to work out the date difference
date1.addNewEvent('change', function (e) {
doDiff();
});
date2.addNewEvent('change', function (e) {
doDiff();
});
})
Fabrik.addEvent('fabrik.form.group.duplicate.end', function (form, event) {
// Replace 204 with the repeat group's id
var groupId = 204;
// Get the number of times the group has been repeated
var repeatMax = form.repeatGroupMarkers[groupId];
// Get the newly added element
var el = form.formElements['join___131___tablename___elementname_' + repeatMax];
// Update the element with the current date/time
el.update(new Date());
});
// replace 1 with the form's id
var formRef = 'form_1';
// Replace with the element name (note it is prefixed with join___JOINID___)
var elementName = 'join___131___regons___country_id';
// Get the form's elements
var elements = Fabrik.blocks[formRef].formElements;
// Filter the form's elements to get every repeating instance of the element
var f = elements.filter(function (element, key) {
return key.contains(elementName);
});
// Loop over each element to hide it
f.each(function(r) {
r.getContainer().hide();
});
// OR loop over each element to show it
// Loop over each element to hide it
f.each(function(r) {
r.getContainer().show();
});
requirejs(['fab/fabrik'], function () {
function total() {
// replace 1 with the form's id
var formRef = 'form_34';
// Replace with the element name
var elementName = 'quote_items___unit_price';
// The element containing the line items total
var totalElement = 'quotes___inv_total';
var total = 0;
// Get the form's elements
var elements = Fabrik.blocks[formRef].formElements,
v;
// Loop over the elements and if their key contains the elementName update the total
elements.each(function (element, key) {
if (key.contains(elementName)) {
v = element.get('value').toFloat();
if (typeOf(v) !== 'null') {
total += v;
}
}
});
// update the Total element
elements.get(totalElement).update(total);
}
// Add events when adding/deleting Groups
Fabrik.addEvent('fabrik.form.group.duplicate.end', function (form, event) {
total();
});
Fabrik.addEvent('fabrik.form.group.delete.end', function (form, event) {
total();
});
document.addEvent('blur:relay(input[name^=quote_items___unit_price])', function () {
total();
})
})
function doCourses(el) {
/*
* els is an array of the full element names of all the dropdowns
* you want to apply the 'exclusive selection' to, and is the only thing you need to change
*/
var els = ['fab_lesson_bookings___morning', 'fab_lesson_bookings___afternoon'];
els.each(function (dd) {
if (dd != el.element.id) {
thisel = el.form.formElements.get(dd).element;
jQuery(thisel.Options).prop('disabled','');
thisel.Options[el.element.selectedIndex].disabled="disabled"
}
}.bind(el));
}
doCourses(this);