You can have an unlimited number of custom fields in HireHop specific to each record, a record being a job, project, test/service, asset, etc. All custom fields can be used in documents, as long as they exist, otherwise they will just be blank.
Currently custom fields are only fully supported in Jobs and Projects. Custom fields can only be used using plugins.
Custom Fields Structure
When saving a record, there is a field called fields. The fields is JSON and is in the following format:
{
“field_name” :
{
“value” : “The value of the field”,
“type” : “The field type, default is text, it can also be number, currency, text, date, html and array”
“format” : “For date type only, eg “ddd, dddddd tt” = “Mon, 1 January 2017 12:00”
}
}
- value is the value of the field in any format.
- type tells HireHop how the field should be treated when merging it into a document. An array field will be displayed as JSON.
- format tells HireHop how to format the field in the document, currently only available dates and is dependent on the users settings and how their date and time formats are set:
- dddddd for a long date (like 1 January 2018)
- ddddd for a short date (like 01/01/2018)
- dddd for the day of the week (like Monday)
- ddd for the short day of the week (like Mon)
- tt for the time (like 12:36).
The format part is only needed for dates and if it is not set, nothing will show. You can merge formats together and add separators, for instance you can use dddd, dddddd tt which will give “Monday, 1 January 2018 12:00” if the user has set a date order as day month year. The value for a date type must be stored in the yyyy-mm-dd hh:mm format.
You can also structure the field like this:
{
“field_name” : “The value of the field”,
“another_field” : 1234567
}
For the above example HireHop will treat the field as text when being merged into a document. If you don’t intend to use the custom fields in documents, the above method is fine and the field value can be anything you want.
Saving The Custom Fields
On all edit forms that support custom fields, there is a div with ID “xxx_fields” or from the edit object you can use the this.fields which is a JQuery variable of the div element. This stores the JSON object in the div’s data-fields attribute, so to get the custom fields, you would call:
var custom_fields = $(“#job_fields“).data(“fields“);
Please note, that all changes must be written to the fields div prior to saving. Also, be very careful not to overwrite and use $.extend to write to it as other plugins may also have their own custom fields.
When the custom fields are saved, they are merged with the existing fields, and any new fields passed with the same name as any existing ones, the new values will be set. To clear all saved custom fields and just save your custom fields, when saving the data, set the overwrite parameter to 1.
When saving the custom fields, for example using /php_functions.job_save.php, only parameters set will be updated, so if you only set the custom_fields post parameter, only the custom fields will change, all the other fields will stay as is.
Printing Custom Fields
All custom fields can be incorporated into documents just like normal fields and are prefixed with a single “_” (underscore) character. For example, for a custom field in a job called “field_name”, you would load it by using the merge field “job:_field_name“.
Naming Custom Fields
Some custom fields in documents merge fields together, for example tests merge with an asset in some document fields, so be careful not to use the same field name in an asset and a test. Also, other plugins maybe added in the future written by yourself or from another source, so add a prefix that denominates you, for example plugins written HireHop by use the “hh_” prefix, so a field written in a plugin by us might be called “hh_NewName”. Field names in document merges are not case sensitive, but they obviously are in JavaScript.
Searchable Custom Field
There is an additional field called CUSTOM_INDEX, that can be used for searching, filtering and listed in search results. The field is a 45 character string value that can be set to NULL. To enable the field to be shown in the search results on the home page, change the allSearchCols global JavaScript variable by adding CUSTOM_INDEX to it:
if(allSearchCols.constructor===Array && doc_type==0 ) {
allSearchCols.push(“CUSTOM_INDEX“);
}
There is also a language setting for the custom field displayed name:
if(typeof(lang[“customIndexTxt“])==”undefined” || lang[“customIndexTxt“]==””) {
lang[“customIndexTxt“] = “Custom field name“;
}
The reason for the testing for undefined or blank above is just in case the user has set it in the language.
You can use the custom searchable field in the page by adding a lookup in the page or the editor. On jobs there is a hidden tile that displays the CUSTOM_INDEX field and can be shown and utilised like so in a plugin:
$(“#job_tile_custom_index“)
.show()
.click(function() {
window.open(“https://www.my_external_app.com?id=“+job_data[“CUSTOM_INDEX“],”newwindow“);
});
To save the CUSTOM_INDEX field in the relevant edit widget, using a custom plugin you can add a form element into the edit widget, for example like so:
// This adds the CUSTOM_INDEX field into the job edit widget
if(typeof($.custom.job_edit)!=”undefined“) {
// Redifine job_edit, move name to after telephone
$.widget(“custom.job_edit“, $.custom.job_edit, {
_init_main: function() {
// Call the old _init_main
this._super(arguments);
// Add an extra edit in the job edit
var table = this.default_disc.closest(“table“);
var tr = $(“<tr>“).appendTo( table);
$(“<td>“, { html: lang.customIndexTxt+ “ :” }).appendTo(tr);
$(“<input>“, {
“name” : “custom_index“, // Parameter to pass when saving
“class” : “data_cell“, // Setting class to data_cell tells HireHop it is a standard data field
“data-field” : “CUSTOM_INDEX“, // Name of the field
“maxlength” : 45 // The CUSTOM_INDEX has a maximum length of 45 characters
})
.appendTo( $(“<td>“).appendTo(tr) );
// Change the memo height to compensate
this.job_edit_memo.height(110);
}
});
}
The CUSTOM_INDEX field is called xxx:custom_index in the document and is passed as a string into the document.