Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
protogrid:script_library [2017-12-15 09:46] 46.140.51.3protogrid:script_library [2017-12-15 09:51] 46.140.51.3
Line 6: Line 6:
  
 Server-ScriptLibraries contain code happening at the server before sending the data to the client. Every [[protogrid:proto|Proto]] can have a server side library attached. Whenever something is done with a [[protogrid:card|Card]] of this Proto on the server, the Server takes the assigned library into account. The server side libraries contain mainly the following functions: on_render, on_save, get_shortname, get_title.  Server-ScriptLibraries contain code happening at the server before sending the data to the client. Every [[protogrid:proto|Proto]] can have a server side library attached. Whenever something is done with a [[protogrid:card|Card]] of this Proto on the server, the Server takes the assigned library into account. The server side libraries contain mainly the following functions: on_render, on_save, get_shortname, get_title. 
-== on_render ==+==== on_render ====
 on_render gets called when opening a new Card. This function can be used for example to [[protogrid:hide_field| hide fields]] of the Card. Inside the on_render function, one has access to the card which is opening as well as to a predicate called "before_first_save" telling you whether the Card was already saved before or not (if not, it is a newly created Card).  on_render gets called when opening a new Card. This function can be used for example to [[protogrid:hide_field| hide fields]] of the Card. Inside the on_render function, one has access to the card which is opening as well as to a predicate called "before_first_save" telling you whether the Card was already saved before or not (if not, it is a newly created Card). 
 <code javascript> <code javascript>
Line 39: Line 39:
 </code> </code>
  
-===== Client ScriptLibrary =====+===== Client-ScriptLibrary =====
 The client-side script library contains all the code happening locally on the clients machine. This contains all the code executed when [[protogrid:trigger|triggered]] by a client action, especially the code that should be executed at [[protogrid:button|button]] clicks. The client-side script library contains all the code happening locally on the clients machine. This contains all the code executed when [[protogrid:trigger|triggered]] by a client action, especially the code that should be executed at [[protogrid:button|button]] clicks.
  
Line 57: Line 57:
 If you want the code to be executed on load of every card, write your code into a separate JavaScript file and load it into the attachments section on the "Code"-Card. This attachments will be loaded whenever any Card is loaded and therefore will be executed on any card load. If you want the code to be executed on load of every card, write your code into a separate JavaScript file and load it into the attachments section on the "Code"-Card. This attachments will be loaded whenever any Card is loaded and therefore will be executed on any card load.
  
-==== Execute JS on field change === =+==== Execute JS on field change ====
  
 To execute some JavaScript when a field value changes, you need to add the following code-snippet to a client-side Script library, which is linked to the Proto with some Trigger. The variable "field_key_my_field" has to be set to the [[protogrid:field|fieldkey]] of the field you want to observe. "my_function()" is the function you want to call when something changes. To execute some JavaScript when a field value changes, you need to add the following code-snippet to a client-side Script library, which is linked to the Proto with some Trigger. The variable "field_key_my_field" has to be set to the [[protogrid:field|fieldkey]] of the field you want to observe. "my_function()" is the function you want to call when something changes.
Print/export