Validation on Total from Related Item Control
Hi,
I have set up a Parent Child relationship using the Related Item Control. This works great for new items and editing. On the Child list, I have an hours column. I need to verfiy that the sum of the hours from the child items does not exceed 40 hours. How can I perform a running total and generate an error if sum of hours > 40? I am using the inline edit mode.
Thanks,
Jon
I have set up a Parent Child relationship using the Related Item Control. This works great for new items and editing. On the Child list, I have an hours column. I need to verfiy that the sum of the hours from the child items does not exceed 40 hours. How can I perform a running total and generate an error if sum of hours > 40? I am using the inline edit mode.
Thanks,
Jon
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi Jon,
If you're using Forms Designer 3.0.8, you can use the following code:
Replace 'Hours' with the internal name of the 'hours' column. If you have multiple Related Items controls in your form, put the appropriate 0-based index into fd.relatedItems(index).
If you're using Forms Designer 3.0.8, you can use the following code:
Code: Select all
fd.onsubmit(function() {
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData;
for (var i = 0; i < rows.length; i++) {
total += rows[i].Hours;
}
if (total > 40) {
alert('Total amount of hours must be less than 40');
return false;
}
return true;
});
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Yes, right! I have not tested my code.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests