How to hide a field in child table view?

In many cases, your application might have a child table, like this:

An example child table in an AppGini application. We want to hide some columns from that table.

Let’s say we want to hide the Company and Open columns from that child table. You can add a CSS rule to hide specific columns from the child table. In the generated hooks/footer-extras.php, add code similar to this:

In the above code, replace:

  • child-table with the name of the child table, “quotes” in the above example.
  • lookup-field with the name of the lookup field in the child table that points to the parent table, “company” in the above example.
  • field-to-hide name of the child table field to hide, “company” in the above example

You can repeat the above rule for every column you want to hide. So, to hide the company and open fields:

The result looks as follows:

Company and Open fields now hidden after applying the above CSS rules.

How to allow numbers only in a field?

Let’s say you have a numeric field, maybe a price, a score or some other field that should contain numbers only. If you set the data type of the field in AppGini (or in your database) to be numeric (INT, DECIMAL, FLOAT … etc) that would allow only numbers to be stored in the database.

But you might still wish to alert the user that only numbers are allowed before she saves the record. Here is how to do it in JavaScript:

First, you should place this code in the hooks/footer-extras.php file:

Next, also in the hooks folder, create a file named tablename-dv.js (where tablename is the name of the concerned table) if it’s not already there, and add this code to it:

Change field1 and field2 in the above code to the actual names of the fields that you want to set to accept only numeric values. Add more lines if you have more fields or remove a line if you have only one numeric field.

The above code would remove any non-numeric characters that the user types, on the fly. And it would still allow negative sign and decimal point.

How to hide the seconds in a time field?

If you have a time field in your AppGini application, it displays a time picker in the detail view like this one:

The timepicker includes seconds. If you wish to hide the seconds part, you could do so by editing the tablename_dv hook. Open the generated hooks/tablename_dv.php file in a text editor (where tablename is the name of the concerned table) and look for the dv function, then add this line inside it:

If you refresh the page, the time field would now look like this, showing no seconds:

Auto save a new record without having to click ‘Save as copy’

An AppGini customer told me recently that he has a table containing only one field, a barcode field, that he uses a barcode scanner to populate. He has thousands of items to enter, and wanted to know if there is someway to expedite his workflow, maybe by avoiding to click ‘Save as copy’ everytime he scans a new barcode.

I suggested the following code to him, to be placed in the hooks/tablename-dv.js (where tablename is the name of the concerned table — create that file if it doesn’t already exist).

Change fieldname in line 2 above to the actual name of the barcode field. The above code checks if the concerned barcode field has been changed. If it has been, the ‘Save as copy’ button (using the #insert selector) is clicked.

Programmatically change the value of an image field in the detail view

In the detail view, if you have some ajax request running in the background that should update your detail view form (or if you do this in the tablename_dv hook), you might already know that you can change the data of a normal text field using this JavaScript code:

But if your field is an image field, the above code won’t work. Try this instead:

Of course, change fieldname in the above code to the actual field name.