JavaScript field: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 1: Line 1:
{{Stamp|2016-08-30|3.9.7|1.0.3}}
{{Stamp|2016-09-10|3.9.7|1.0.3}}
The value of the field will depend on the result of execution of the script preset in the settings of the field and executed in the entry context.
 
The value of the field will be the result of execution of the script defined in the field and executed in the entry context.


'''[https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7 JavaScript 1.7]''' is used for scripts. The current version supports only core methods of the language.
'''[https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7 JavaScript 1.7]''' is used for scripts. The current version supports only core methods of the language.


A script may consist of multiple operations but only the result of the last operation will be entered into the field. Example:
A script may consist of multiple operations, but only the result of the last operation will be entered into the field. For example:
<source lang="javascript">
<source lang="javascript">
var i = 1 + 1
var i = 1 + 1
i + 1
i + 1
</source>
Result will be: 3
Result will be: 3
</source>


== Fields of an entry ==
== Fields of an entry ==
Line 27: Line 27:
| Date , Date/Time, Time || [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date '''Date''']
| Date , Date/Time, Time || [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date '''Date''']
|-
|-
| Boolean || [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean '''Boolean''']
| Checkbox (Boolean) || [https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean '''Boolean''']
|-
|-
| Multiple-choice list, Checkboxes || [https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array '''Array of String''']
| Multiple-choice list, Checkboxes || [https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array '''Array of String''']
|-
|-
| Link to entry || Array of entries. Each array element has method field for access to values of linked entry.
| Link to entry || Array of entries. Each array element has a method field for access to values of the linked entry.
|}
|}


== Time of script execution ==
== Time of script execution ==
A script can be executed both when an entry is created or changed and when it is displayed.<br />
A script can be executed both when an entry is created or changed and when it is displayed.
 
The time of script execution is set by the toggle button ''Execute script real time'' on the field edit screen.
The time of script execution is set by the toggle button ''Execute script real time'' on the field edit screen.
It is reasonable to enable this option if your script contains functions that depend on the current time. Online execution in case of a large number of entries can significantly increase the time required to open the library.
It is reasonable to enable this option if your script contains functions that depend on the current time.
Online execution in case of a large number of entries can significantly increase the time required to open the library.


== Functions to work with the date ==
== Functions to work with the date ==
You can enable integrated library [http://momentjs.com/ '''moment.js'''] to work with the date and time. Click '''''JavaScript Libraries''''' and choose '''''moment.min.js'''''.
You can enable the integrated library [http://momentjs.com/ '''moment.js'''] to work with the date and time. Click '''''JavaScript Libraries''''' and choose '''''moment.min.js'''''.


Some examples. If record contains the data field whose value is 18 March 2016 14:55
Some examples. If a an entry contains the field whose value is 18 March 2016 14:55


Example of Format dates
Example of Format dates