Plugin JQ | |
This wiki plugin, introduced in Tiki3, allows jQuery JavaScript code to be inserted on a page. See also PluginHTML and PluginJS. |
1.1. Requirements | |
The jQuery feature must be enabled at Control Panels > Features > Experimental > jQuery (checkbox). |
1.2. Parameters | |||||||||||||||||||||||||
Add jQuery JavaScript code Introduced in Tiki 3. Go to the source code Preferences required: wikiplugin_jq
Syntax changed since Tiki 7 Keep in mind that default syntax for tracker fields changed since Tiki7, so that when referring them from within plugin jQuery, you have to update the syntax.
For more information, read: http://doc.tiki.org/Tiki7#Upgrade_notes And basic syntax changed after Tiki 6: A Simple jQuery line of code looks like this: Copy to clipboard
Copy to clipboard
|
1.3. Examples | |
1.3.1. Simple one | |
A Simple jQuery line of code looks like this: Copy to clipboard
|
1.3.2. Use jQuery Date Picker to input date in a form | |
Copy to clipboard
For example here we changed the date format for yyyy-mm-dd Copy to clipboard
|
1.3.3. Using JQ plugin to enhance tracker plugin | |
You can show or hide fields (the whole div containing it) based on another input condition.
Copy to clipboard
|
1.3.4. Special notes: | |
When following above guide, you can only call the included script from the getScript handler. That means, you cannot just include the script under look and feel area, and then use that script from the JQ plugin - the order of loading the script and using it, will conflict. In short: Call your custom script from the getScript handler.~/tc~ |
1.3.5. Using JQ plugin to enhance Pretty Tracker forms | |
JQ plugin won't substitute the pretty tracker form, fields or design. In one sentence; With JQ plugin you can add functionality to an already working pretty tracker. A good practice is to create your tracker, your wiki page, do the design you need and test that everything is working fine. Then without touching what's been already done you can add the JQ plugin at the bottom of the wiki page. Fields IDs are a little different than the ones used in the tracker or the pretty tracker. For instance a tracker field id 1 which is a text field should specify as |
1.3.6. Prefill tracker fields | |
1.3.6.1. Directly at the wiki pageBasic Example A
Copy to clipboard
Copy to clipboard
You can use some value defined in some other HTML Copy to clipboard
Copy to clipboard
Copy to clipboard
Copy to clipboard
Copy to clipboard
1.3.6.2. By means of a wiki page used as a smarty template ('Pretty trackers')This case is needed when you are adding some prefill by means of a smarty template which resides on a wiki page. This is very useful when you use PluginR in advanced mode with Pretty Trackers, for instance, to mix R code and HTML forms to collect parameter data managed by Tiki trackers. The Smarty template allows inserting data from tracker item fields in R scripts. Example: Copy to clipboard
|
1.3.7. Pre-fill with CSS styles | |
The pre-filling performed by jQuery can be done with some style, to indicate the user that this content comes from a suggestion when the field in the tracker form is empty (yet) for that item. Thus, in the first example above ("Prefill tracker fields > Directly at the wiki page"), if you want those values to be prefilled in your form only when there is not previously saved content in that tracker field for that item and with some CSS style like Copy to clipboard
|
1.3.8. Conditional display of fields | |
1.3.8.1. Example 1Imagine that you have a form with 15 fields. Field number 10 is a checkbox checked by default, and you want that when field 10 is checked, field 11 (a text area, for instance) is shown. But when field 10 is not checked, fields 12, 13, 14 & 15 are shown instead. You can get that behavior with the following jQuery syntax: Copy to clipboard
| |
1.3.9. Empty textarea field on load | |
If textarea tracker field is number 64, this would be the code: Copy to clipboard
|
1.3.10. Show text inputs with content but non-editable | |
In some cases you may want to show the contents of some tracker field to the user without that chance to edit it. You can achieve so with this simple jQuery code below, for a tracker field number 1, in a wiki page with PluginTracker and some itemId passed in the URL: Copy to clipboard
|
1.3.11. Disable some checkboxes when no content found in the corresponding cell | |
The code below disabled checkboxes from the items in a table generated with PluginListExecute where the 7th column (6th for jQuery, since it starts counting from 0) has no content in the cell. In addition, it disables the select all checkbox, since for some reason allowed to select the disabled ones by the time of this writing: Copy to clipboard
|
1.3.12. Changes in dropdown selectors with Chosen jQ plugin | |
You need to add some ".trigger('chosen:updated');" From Copy to clipboard
Copy to clipboard
|
1.3.13. Disable dropdown selectors with Chosen jQ plugin | |
You can disable the field 162 (being a dropdown field), when chosen jq plugin is in use, with a syntax like: Copy to clipboard
|
1.3.14. Reduce the selection in a select field | |
Copy to clipboard
Copy to clipboard
|
1.3.15. Hide fields in Tiki 15+ (Bootstrap) | |
Use the CSS selector for the field 162 (being a dropdown field), like: Copy to clipboard
|
1.3.16. Hide fields in Tiki18+ (Bootstrap) | |
Copy to clipboard
|
1.3.17. Advanced: jQuery in Static Text tracker field to synchronize user selector tracker fields | |
From the use case partly covered in the profile "Custom_Work_Pricing" 1.3.17.1. Simplest caseCopy to clipboard
1.3.17.2. Updating some status in one other trackerAnd in case you also want to update some field from another tracker, you can do so with an ajax call fired from inside the jquery plugin. See this enhanced version: Copy to clipboard
1.3.17.3. Updating some status value in two other trackersAnd if you want to update several other trackers, not just one, you could use this other syntax. Note that it updates also tracker 11, field 320 wth value 1: Copy to clipboard
|
1.3.18. Make a clickable button with a custom icon | |
For when using PluginButton isnt possible for whatever reason. Copy to clipboard
In the example above, we want the div to act as the button but the hyperlink is only on the 'click me' text. By adding a click event on the div, you can fetch the hyperlink which now make the whole div clickable. |
1.3.19. Allow only lower case letters in a tracker field | |
In this example we want to allow the user to type only lowercase, so that we replace the typed letters to lowercase at typing time, in the search form produced by PluginCustomSearch: Copy to clipboard
This is useful with search/folter boxes (from PluginCustomSearch, PluginTrackerFilter or similar use cases with filter fields) in which the stored content or text strings are in lowercase, and the search is case sensitive, so that searching the uppercase versions of the string will show no matches.
|
1.3.20. Empty Tracker date (DatePicker) field when used as filter | |
In some edge cases, you may want to empty a date (DatePicker) tracker field in form to filter records from a tracker. This can happen, for instance, in cases when you wnat to have PluginPivotTable show a filter field in top of the results. Example: Copy to clipboard
Copy to clipboard
|
1.3.21. Force search module filter for specific features objects | |
The Search Module options allows a filter to be displayed to search object from a specific feature. For exemple you can search for a string but only for Articles, Forums, Wiki Pages, etc. However it is up to the user to set it. Using JQuery you can force the filter for a specific feature and with some CSS styles you can hide the label and filter selector. The user won't see anything but a search field. Copy to clipboard
Copy to clipboard
|
1.4. jQuery on Custom Search results | |
If you want to run some jquery code on the results of the CustomSearch, you need to do it in a different way than usual, since Custom Search loads results by Ajax and doesn't allow to run javascript code by default. See param "callbackscript" at the CustomSearch documentation page to see how to avoid this issue and get your jQuery run. |
1.5. Tracker Field Validation | |
See also: Tracker Field Validation > Adding custom per-page validation |
More jQuery tips & tricks | |
For more tips and tricks using jQuery, visit:
For more information on jQuery selectors:
|