field_class
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
field_class [2019/10/24 20:25] – created sahl | field_class [2022/05/23 10:41] (current) – [HTML composition of form fields] sahl | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Field* class ====== | ====== Field* class ====== | ||
- | The Field* complex of classes are all different input fields to insert into a [[class_form|Form]]. There are both simple fields and more complex fields. | + | The Field* complex of classes are all different input fields to insert into a [[form class|Form]]. There are both simple fields and more complex fields. |
===== Base class ===== | ===== Base class ===== | ||
Line 11: | Line 11: | ||
</ | </ | ||
- | where $label is the field label, $name is the field name and options can be one of the following: | + | where $label is the field label, $name is the field name and $options can be any of the following: |
+ | ^autofocus|If set to true, then this field is automatically focused on page load.| | ||
^class|Additional classnames to apply to the input field (as an array).| | ^class|Additional classnames to apply to the input field (as an array).| | ||
- | ^containerclass|Additional classnames to apply to the general container of the form field (as an array).| | + | ^container-class|Additional classnames to apply to the general container of the form field (as an array).| |
+ | ^container-style|Styles to add to the form field container div.| | ||
+ | ^dont-clear|If this is set it instructs Platform **not** to clear the form value if the form is reset (using the Platform reset function)| | ||
^heading|If the field requires a heading, this can be provided as a string.| | ^heading|If the field requires a heading, this can be provided as a string.| | ||
- | ^options|If the field requires different options, these can be provided as an array.| | + | ^label-alignment|Select how to align the label of the field. Can be: //auto//, //top//, //bottom//, //left//, //right// or // |
- | ^required|If this is true, then the form is required.| | + | ^options|If the field requires different options, these can be provided as an array here.| |
+ | ^required|If this is true, then the field is required | ||
^value|Provides a value to the field.| | ^value|Provides a value to the field.| | ||
Other options proved are applied directly to the resulting html tag as a property-value pair, so '' | Other options proved are applied directly to the resulting html tag as a property-value pair, so '' | ||
- | ===== HTML properties | + | ===== HTML composition of form fields |
- | The resulting HTML tags will typically | + | The input field itself |
<code php> | <code php> | ||
Line 35: | Line 39: | ||
<code html> | <code html> | ||
<form id=" | <form id=" | ||
+ | ... | ||
<input name=" | <input name=" | ||
+ | ... | ||
</ | </ | ||
</ | </ | ||
+ | One or more helper div's are created around the input field. There is always an outer div containing the entire field structure. This outer div will have the same id as the input field, but with // | ||
+ | |||
+ | Inside this div, there can be up to three divs with these class names. | ||
+ | |||
+ | ^// | ||
+ | ^// | ||
+ | ^// | ||
+ | |||
+ | Their presence and individual placement can vary depending on label alignment. Example of complete field output: | ||
+ | |||
+ | <code html> | ||
+ | <form id=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <label for=" | ||
+ | <div class=" | ||
+ | <input name=" | ||
+ | <div class=" | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Width and sizes ==== | ||
+ | |||
+ | The field (which is considered both the field and the label will obtain 100 % of the available width). | ||
+ | |||
+ | The field itself can be one of three sizes. | ||
+ | |||
+ | A normal size field will be 280 px wide. | ||
+ | A small size field will be 120 px wide. | ||
+ | A tiny size field will be 50 px wide. | ||
+ | |||
+ | This can be overwritten by the field-width parameter. If there isn't enough free space the field will scale down. | ||
+ | |||
+ | The label will always be 130 px wide and if the label exceeds that amount it will appear over several lines. This can be overwritten by the label-width parameter. | ||
+ | The label will always have a 0 px padding before the text and a 5 px padding after the text. | ||
===== Form fields ===== | ===== Form fields ===== | ||
Here we go over each form field. | Here we go over each form field. | ||
+ | |||
+ | ==== FieldButton ==== | ||
+ | |||
+ | Provides an input button field which doesn' | ||
==== FieldCheckbox ==== | ==== FieldCheckbox ==== | ||
Line 51: | Line 100: | ||
This provides a combobox field which is a field that allow any value, but will suggest values as the user starts typing. This field uses Jquery autocomplete and takes an option named '' | This provides a combobox field which is a field that allow any value, but will suggest values as the user starts typing. This field uses Jquery autocomplete and takes an option named '' | ||
+ | ==== FieldComponent ==== | ||
+ | |||
+ | This field allows to add [[Component Class|Components]] as form fields. Please refer to [[FieldComponent Class]] for using this feature. | ||
==== FieldDatarecordCombobox ==== | ==== FieldDatarecordCombobox ==== | ||
- | This is a variation of the Combobox which suggest values from a [[class_datarecord|Datarecord class]] and also only validates if the typed value can be resolved to an object of the given class. It takes an option named '' | + | This is a variation of the Combobox which suggest values from a [[datarecord_class|Datarecord class]] and also only validates if the typed value can be resolved to an object of the given class. It takes an option named '' |
The field returns the key field ID of the selected Datarecord. | The field returns the key field ID of the selected Datarecord. | ||
Line 69: | Line 121: | ||
This provides an interface for selecting a file. An existing file can be displayed in the field, so the user can choose to keep it, delete it or change it to another file. Files are uploaded on-the-fly. | This provides an interface for selecting a file. An existing file can be displayed in the field, so the user can choose to keep it, delete it or change it to another file. Files are uploaded on-the-fly. | ||
- | The File field is a little special to use. To set a value in the field, one should pass the '' | + | The File field is a little special to use, as the output differs from the input. As an input one should pass the '' |
- | When getting the value from the field (after the form is posted) | + | But when content is returned |
+ | |||
+ | ^mimetype| The mimetype of the file.| | ||
+ | ^status | ||
+ | ^original_file| The original name of the file.| | ||
+ | ^temp_file| The location of a temporary file with file data of the uploaded file (if status is // | ||
+ | |||
+ | This array can be passed directly into a [[datarecord_class|Datarecord]] file field which will sort everything out automatic, but needs a little more work when used manually. | ||
==== FieldHTML ==== | ==== FieldHTML ==== | ||
Line 97: | Line 156: | ||
==== FieldMultiplier ==== | ==== FieldMultiplier ==== | ||
- | The Multiplier is a field which allow one to add several fields to it and then it will render each of these fields. If one of these fields are filled, a new section will be spawned with the same fields, so it is used for form sections which needs to appear as many time as they are needed. | + | The Multiplier is a field which allow one to add several fields to it and then it will render each of these fields. If one of these fields are filled, a new section will be spawned with another copy of the same fields, so it is used for form sections which needs to appear as many time as they are needed. |
The field return an array with an element for each time a section was spawned, where each element is the value of the contained fields. | The field return an array with an element for each time a section was spawned, where each element is the value of the contained fields. | ||
Line 137: | Line 196: | ||
</ | </ | ||
- | Multiple multipliers can be nested | + | Multiple multipliers can be nested. |
==== FieldNumber ==== | ==== FieldNumber ==== | ||
Line 145: | Line 204: | ||
==== FieldPassword ==== | ==== FieldPassword ==== | ||
- | A field which is used for passwords. Values passed to this field is never displayed and is only considered regarding if they are there or not. If there is a value, the field will display XXXXXX, and if there isn't a value, the field will be empty. | + | A field which is used for passwords. Values passed to this field are never displayed |
When extracting a value from the field, '' | When extracting a value from the field, '' | ||
+ | |||
+ | This behavior is directly compatible with the Datarecord object and values can be passed into a Datarecord password field. | ||
==== FieldSelect ==== | ==== FieldSelect ==== | ||
Line 164: | Line 225: | ||
This renders a multi-line textarea. | This renders a multi-line textarea. | ||
+ | |||
+ | ===== Creating your own form field ===== | ||
+ | |||
+ | To create your own form field, you need to extend the '' | ||
+ | |||
+ | ==== Rendering input ==== | ||
+ | |||
+ | Overwrite the '' | ||
+ | |||
+ | <code php> | ||
+ | public function renderInput() { | ||
+ | echo '< | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Validating input ==== | ||
+ | |||
+ | Overwrite the '' | ||
+ | |||
+ | This function should accomplish two things. First it should validate if the input is valid for the field. If the input is valid the function should return true. If the input isn't valid, an error should be raised by the field, which could be done like: | ||
+ | |||
+ | <code php> | ||
+ | $this-> | ||
+ | </ | ||
+ | |||
+ | ...and the function should return false. | ||
+ | |||
+ | Furthermore the value intended as the real output from the form should be saved in the '' | ||
+ | |||
+ | ==== Using script ==== | ||
+ | |||
+ | If the field requires javascript, this can be included using '' | ||
+ | |||
+ | <code javascript customcomponent.js> | ||
+ | addCustomPlatformFunction(function(item) { | ||
+ | $(' | ||
+ | } | ||
+ | </ | ||
+ | ==== Other services of the Field class ==== | ||
+ | |||
+ | The field class takes care of handling the label of the field. | ||
+ | |||
+ | You can get your field to work with the easy html form files, by naming your class Field* and adding the namespace of your class to the Form class, by using the '' | ||
+ | |||
+ | So if you do this: | ||
+ | |||
+ | <code php> | ||
+ | namespace MyNameSpace; | ||
+ | |||
+ | class FieldCustomField { | ||
+ | ... | ||
+ | } | ||
+ | |||
+ | $form = new Form(...); | ||
+ | $form-> | ||
+ | |||
+ | </ | ||
+ | |||
+ | ...you can create a form html field like: | ||
+ | |||
+ | <code html test.form> | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | ==== Best practices ==== | ||
+ | |||
+ | If you need to modify base field parameters such as adding a new class to the field, do this in the constructor with the proper functions instead of doing it in the '' |
field_class.1571948752.txt.gz · Last modified: 2019/10/24 20:25 by sahl