Child table - "Add New" Button hide with condition

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
pandiyan
Posts: 7
Joined: 2021-12-30 11:07

Child table - "Add New" Button hide with condition

Post by pandiyan » 2021-12-31 06:25

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.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Child table - "Add New" Button hide with condition

Post by pbottcher » 2021-12-31 09:09

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
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pandiyan
Posts: 7
Joined: 2021-12-30 11:07

Re: Child table - "Add New" Button hide with condition

Post by pandiyan » 2022-01-21 06:53

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>

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Child table - "Add New" Button hide with condition

Post by pbottcher » 2022-01-22 14:59

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pandiyan
Posts: 7
Joined: 2021-12-30 11:07

Re: Child table - "Add New" Button hide with condition

Post by pandiyan » 2022-02-01 07:20

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')

}
})
})

Post Reply