Module CustomFields Dev: Difference between revisions

Jump to navigation Jump to search
Line 341: Line 341:
Note: this method will always return an array of records object, for more consistency (and this is the main difference with fetch(null) ).
Note: this method will always return an array of records object, for more consistency (and this is the main difference with fetch(null) ).


== Printing custom fields ==
== Input forms for custom fields ==


The API can also automatically manage the printing of custom fields, and also the management of the input forms for users to input new values, with the best adapted HTML form based on the custom field's data type.
The API provides some neat ways to automatically manage the input forms for users to input new values, with the best adapted HTML form based on the custom field's data type.


=== Input forms ===
The following methods will print input fields that are best adapted to the SQL data type of your custom fields as well as figure out the possible values and even format them (for example: a not null enum will be printed as a HTML select list without an empty option; fetch automatically remote columns for constrained fields and show them in a select).
 
CustomFields provides a neat way to print input fields that are adapted to the SQL data type of your custom fields as well as the possible and formatted values (for example: a not null enum will be printed as a HTML select list without an empty option).


So you don't have to bother how your data will be presented to the user nor how it will be processed.
So you don't have to bother how your data will be presented to the user nor how it will be processed.


==== Printing an input form adapted to the field's data type ====
=== Printing an input form adapted to the field's data type ===


showInputField() is a sort of converter customfieldstructure -> HTML input field.
showInputField() is a sort of converter customfieldstructure -> HTML input field.


Use the showInputField() method to print the right input form for a custom field.
Use the '''showInputField()''' method to print the right input form for a custom field.


<source lang="php">
<source lang="php">
Line 386: Line 384:
</source>
</source>


==== Printing an input form for a custom field ====
Note: for constrained fields, if the name follows the convention of '''Smart Value Substitution''' (ie: remote columns names are included in the custom field's name), showInputField() will '''automatically fetch the remote values, format them, and present them''' in a HTML select.
 
=== Printing an input form for a custom field ===


showInputForm() is a function used to print a single (and only one!) custom field with an adapted HTML input field, but enclosed by a HTML form. This is used for example when you want to allow to edit a single custom field but not the others.
'''showInputForm()''' is a function used to print a single (and only one!) custom field with an adapted HTML input field, but enclosed by a HTML form. This is used for example when you want to allow to edit a single custom field but not the others.


showInputForm() is in fact a wrapper for showInputField(), thus it will call showInputField() and simply enclose it by a form.
showInputForm() is in fact a wrapper for showInputField(), thus it will call showInputField() and simply enclose it by a form.
Line 395: Line 395:
print $customfields->showInputForm($id, $field, $currentvalue=null, $idvar='id', $page=null, $moreparam='');
print $customfields->showInputForm($id, $field, $currentvalue=null, $idvar='id', $page=null, $moreparam='');
</source>
</source>
== Printing custom fields in documents ==
The API can also automatically manage the printing and formatting of custom fields in your ODT, PDF and HTML documents.
=== Printing in HTML ===
You can either just print the value as-is, or pass them through the printField() or simpleprintField() function to format them (very useful for constrained fields) - see below.


=== Printing in documents ===
=== Printing in documents ===
printField()
=== Simple printing in documents ===


simpleprintField() simpleprintFieldPDF()
simpleprintField() simpleprintFieldPDF()
findLabel() findLabelPDF()
 
=== Find the label ===
 
Finding the label of a custom field might not be as simple as it seems. First, values of properties objects may be easily used, but their name (key) is a worst job. Secondly, custom fields' labels can be translated, and the following functions are expressly made for that purpose.
 
So if you want to print a custom field's label with translation (multilingual) support, just use the '''findLabel()''' method:
 
<source lang="php">
$customfields->findLabel();
</source>
 
As for the other printing methods, you also have the '''findLabelPDF()''' wrapper method to easily print labels that with characters encoded for PDF.


= Facade API =
= Facade API =
439

edits

Navigation menu