Page 1 of 1
Child table - "Add New" Button hide with condition
Posted: 2021-12-31 06:25
by pandiyan
Hi All,
I have `ticket` and `ticket_update` tables
if the `ticket`.`flag`="1" in condition `ticket_update` Child table - "Add New" Button to be hide
Thanks in Advance.
Re: Child table - "Add New" Button hide with condition
Posted: 2021-12-31 09:09
by pbottcher
Hi,
you can either check in the hooks/TABLENAME.php -> _dv function the condition and set the permissions to the child table accordingly,
or you can use JS on the detailview. You need to wait till the child table is loaded and then remove the Add New button. The second solution will require that you check the creation of the child record, as a user could bypass the missing "Add New" Button.
Hope that gives you a starting point
Re: Child table - "Add New" Button hide with condition
Posted: 2022-01-21 06:53
by pandiyan
I had try with this below code, but its not working.
<script>
$j(function(){
$j('#status').each(function(){
var status = $j(this).text();
if (status =='Closed'){
$j('.btn.btn-success.hspacer-sm.vspacer-md').addClass('hidden');
alert($j('#status').text());
}
else {
$j('.btn.btn-success.hspacer-sm.vspacer-md').removeClass('hidden');
alert($j('#status').text());
}
})
})
</script>
Re: Child table - "Add New" Button hide with condition
Posted: 2022-01-22 14:59
by pbottcher
Hi,
once you checked if the status == 'Closed' you will have to check if the button is already loaded. The child table is loaded later, so your code would probably not catch the button yet.
Re: Child table - "Add New" Button hide with condition
Posted: 2022-02-01 07:20
by pandiyan
Thanks for the clue...
function wait_for(data,callback,time=60) {
if($j(data).length != 0) {
callback();
return;
}
else {
setTimeout(function() {
wait_for(data,callback, time);
}, time);
}
}
$j(function() {
wait_for(".btn.btn-success.hspacer-sm.vspacer-md", function() {
if($j('#status').text() == 'Closed'){
$j('.btn.btn-success.hspacer-sm.vspacer-md').addClass('hidden')
}
})
})