You can create some files with specific names inside the hooks folder that your AppGini-generated application would use to perform a specific task. These files are optional, meaning that if they exist, your application will automatically use them to alter a default behavior. But if they don’t exist, the default behavior will apply.

tablename-dv.js: modifying the behavior of the detail view through javascript

If you create a file in the hooks folder and name it tablename-dv.js (where tablename is the name of a table in your application), AppGini will automatically load that file and execute it as a javascript file in the browser whenever the detail view of the specified table is displayed. This is very useful to execute javascript code in the detail view.

For example, let’s assume we have an exams table, and a score field in that table. We want to limit the contents of that field to a certain range of numbers, and warn the user if he enters a number outside that range. To do so, we could add some javascript code like the following in the magic hooks/exams-dv.js file.

$j(function() { 
    $j('#score').on('change', function() {
        var score = parseInt($j('score').val());
        if(isNaN(score) || score > 100 || score < 0){
            alert('Score must be between 0 and 100!');
            $j('#score').focus();
        }
    });
});

Line 1 in the code above makes sure this code won’t be executed until the page content and jQuery are loaded to avoid triggering an error on some browsers.

tablename-tv.js: modifying the behavior of the table view through javascript

As of AppGini 5.30, if you create a file in the hooks folder and name it tablename-tv.js (where tablename is the name of a table in your application), AppGini will automatically load that file and execute it as a javascript file in the browser whenever the table view of the specified table is displayed. This is very useful to execute javascript code in the table view.