Get a count of attachments
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Hello, Katy!
I think it should be possible. You can simply count amount of items in Related Items control and remove Add button once Related Items count reaches 25. It will have to use an interval timer, since you need to constantly check the amount of items in Related Items control.
I assume you've followed this instruction to only display items that are actually related to this specific Registration Form - https://spform.com/documentation/relate ... gular-mode If not, please follow it, otherwise you'll limit total number of items in the list, not just the ones related to this specific Registration Form.
To make sure nobody can add more than 25 items, add this code to the JavaScript editor in Forms Designer:
Every half a second, it will check amount of items in Related Items control and if it's 25 or more, it will hide button to add more. If it's less than 25 items, it will display this button again, in case the user has deleted some of the items. It's still possible to delete items, but not possible to add after 25.
Finally, you can also add this to your code. It will make sure that no matter what, the user won't be able to save the Form with more than 25 items, even if somehow managed to add more.
It's mostly a precaution and not necessary, but might be useful, if user clicks add new in less than half a second. Though you can easily adjust the interval timer to your liking.
I think it should be possible. You can simply count amount of items in Related Items control and remove Add button once Related Items count reaches 25. It will have to use an interval timer, since you need to constantly check the amount of items in Related Items control.
I assume you've followed this instruction to only display items that are actually related to this specific Registration Form - https://spform.com/documentation/relate ... gular-mode If not, please follow it, otherwise you'll limit total number of items in the list, not just the ones related to this specific Registration Form.
To make sure nobody can add more than 25 items, add this code to the JavaScript editor in Forms Designer:
Code: Select all
function checkRelatedItems(){
if ($('.related-items .ms-listviewtable > tbody > tr').length >= 25) {
$('.ms-list-addnew').hide();
}
else{
$('.ms-list-addnew').show();
}
}
var timerId = setInterval(function() {
checkRelatedItems();
}, 500);
Finally, you can also add this to your code. It will make sure that no matter what, the user won't be able to save the Form with more than 25 items, even if somehow managed to add more.
Code: Select all
fd.onsubmit(function() {
if ($('.related-items .ms-listviewtable > tbody > tr').length > 25) {
alert('Too many items added, please delete them until no more than 25 left');
return false;
}
return true;
})
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 17 guests