Change a database value before display

Change a database value before display

Postby agnar » Fri Jan 03, 2014 7:22 pm

Basically, I need to change the value of a database field before it is displayed in an edit form.

For, examle, I might set a date to the current date (say, as a last modification date)

I can set a default value for a new record easilly, but can't figure out how to do it on an existing record.

Posts: 37
Joined: Mon Apr 22, 2013 6:28 am

Re: Change a database value before display

Postby massiws » Sat Jan 04, 2014 1:05 am

Agnar, you could use nuLoadThis() function in Custom Code > Javascript.
For example:
Code: Select all
if ( $("#your_field").val() === '' ) {
  $("#your_field").val('default value');

If the field isn't on the form you can:
  • use AJAX call to get the value from DB;
  • load the value field in a hidden field on the form.

If you change the value via Javascript, remember to update the field in DB using uDB() function.

Hope this helps,
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Return to Custom Code