Difference between revisions of "Json field"

From EPrints Documentation
Jump to: navigation, search
(Compatible Field Types)
m (Installation)
 
(5 intermediate revisions by the same user not shown)
Line 13: Line 13:
  
 
=== Installation ===
 
=== Installation ===
This module requires the <tt>HTML::Entities</tt> and <tt>JSON::Parse</tt> Perl libraries installed.
+
This module requires the <tt>HTML::Entities</tt> and <tt>JSON::Parse</tt> Perl libraries installed. Also requires <tt>jquery</tt> ingredient to be enabled in your [[EPrints_Glossary#Flavour|flavour's]] inc file.  If you want to use the <tt>richtext</tt> sub-field type a [https://www.tiny.cloud/docs/tinymce/6/cloud-quick-start/ TinyMCE script] to be included either in a <tt>&lt;script&gt;</tt> tag in the archive's template or downloaded into the archive's <tt>cfg/static/javascript/auto/</tt> directory.
  
 
=== Usage ===
 
=== Usage ===
Line 35: Line 35:
 
         {
 
         {
 
             name => "subfield4",
 
             name => "subfield4",
             type => "namedset"
+
             type => "namedset",
 
             set_name => "example_set"
 
             set_name => "example_set"
 
         }
 
         }
Line 41: Line 41:
 
  }
 
  }
  
=== Compatible Field Types ===
+
=== Compatible Sub-field Types ===
For the sub-fields the following field types are currently compatible.  These are separate and should not be confused with EPrints MetaField types:
+
For the sub-fields the following sub-field types are currently compatible.  These should not be conflated with EPrints MetaField types, of which some are emulated by the types below but are configured differently:
 
* '''<tt>text</tt>''' - A single line text, (i.e. HTML <tt>&lt;input type="text"&gt;</tt>)
 
* '''<tt>text</tt>''' - A single line text, (i.e. HTML <tt>&lt;input type="text"&gt;</tt>)
 
* '''<tt>number</tt>''' - A numerical text field, (i.e. HTML <tt>&lt;input type="number"&gt;</tt>)
 
* '''<tt>number</tt>''' - A numerical text field, (i.e. HTML <tt>&lt;input type="number"&gt;</tt>)
* '''<tt>longtext field</tt>''' - a multi-line text field (i.e. HTML <tt>&lt;textarea&gt;</tt>)
+
* '''<tt>longtext</tt>''' - a multi-line text field (i.e. HTML <tt>&lt;textarea&gt;</tt>)
 
* '''<tt>boolean</tt>''' - a checkbox field (i.e. HTML <tt>&lt;input type="checkbox"&gt;</tt>)
 
* '''<tt>boolean</tt>''' - a checkbox field (i.e. HTML <tt>&lt;input type="checkbox"&gt;</tt>)
 
* '''<tt>richtext</tt>''' - a multi-line text field with a WYSIWYG editor
 
* '''<tt>richtext</tt>''' - a multi-line text field with a WYSIWYG editor

Latest revision as of 10:01, 10 April 2023

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


Metadata Fields: Arclanguage - Base64 - Bigint - Boolean - Compound - Counter - Dataobjref - Date - Decimal - Email - Fields - Float - Id - Idci - Image - Int - Itemref - Keywords - Langid - Longtext - Longtext_counter - Multilang - Multipart - Name - Namedset - Pagerange - Recaptcha - Recaptcha3 - Relation - Search - Secret - Set - Storable - Subject - Subobject - Text - Time - Timestamp - Url - Uuid

Inheritance

Description

Like a Compound field, this field is designed to have a number of subfields which are all stored and displayed under the same parent field. However, unlike the Compound field, instead of storing each one in its own field or table, we store all the subfields in a single database field as a JSON string.

Installation

This module requires the HTML::Entities and JSON::Parse Perl libraries installed. Also requires jquery ingredient to be enabled in your flavour's inc file. If you want to use the richtext sub-field type a TinyMCE script to be included either in a <script> tag in the archive's template or downloaded into the archive's cfg/static/javascript/auto/ directory.

Usage

The field works by providing a json_config. parameter, for example:

{ 
    name => "fieldname", 
    type => "json", 
    json_config => [
        {
            name => "subfield1",
            type => "text"
        },
        {
            name => "subfield2",
            type => "number"
        },
        {
            name => "subfield3",
            type => "richtext"
        },
        {
            name => "subfield4",
            type => "namedset",
            set_name => "example_set"
        }
    ],
}

Compatible Sub-field Types

For the sub-fields the following sub-field types are currently compatible. These should not be conflated with EPrints MetaField types, of which some are emulated by the types below but are configured differently:

  • text - A single line text, (i.e. HTML <input type="text">)
  • number - A numerical text field, (i.e. HTML <input type="number">)
  • longtext - a multi-line text field (i.e. HTML <textarea>)
  • boolean - a checkbox field (i.e. HTML <input type="checkbox">)
  • richtext - a multi-line text field with a WYSIWYG editor
  • namedset - a set of options (i.e. HTML <select&gt

These all render as their comparative EPrints MetaFields would, however are rendered by JavaScript instead of the standard EPrints form renderer.

The corresponding phrases for each subfield are in the format:

  • eprint_fieldname_${fieldname}_${subfieldname}
  • eprint_fieldhelp_${fieldname}_${subfieldname}

Table View

The JSON field can also be used to render a table, with a fixed number of rows. In this scenario, the JSON string stored is a JSON array.

Use render_table to turn on the table mode, and table_row_count to specify the number of rows.

In some tables, you may want to skip certain subfields - e.g. the third row doesn't have subfield 3. If the value of the subfield is __json_field_control__skip, the subfield will not render.

If using resizeable richtext in your tables, you can use the reset button to put the fields/table columns back to their default size.

If you set table_allow_hide_rows to be true, you get a select to select which rows you want to appear and which not. table_show_hide_rows default is true. This will show the selector. Allows you to hide on some views, e.g. allowing certain workflows to determine rows shown, and certain to edit values

If you set table_hide_table to be true, the table is hidden, e.g. allowing certain workflows to determine rows shown, and certain to edit values

If you set table_hide_rows_render_js, you can provide custom JavaScript to render the hide rows selector and how the json is updated.

List View

The JSON field can also be used to display the fields in multiple columns, instead of the standard one-after-the-other. This is helpful in scenarios where you have lots of small fields, e.g. a series of boolean checkboxes.

Use display_as_list to turn on the list mode, and `display_as_list_cols` to specify the number of columns you want.

Lookup

You can provide an input_lookup_url as per standard MetaFields.

When added, each subfield will have lookup capabilities. It will send the following as parameters to the input_lookup_url

  • q - the query
  • field - the json field name
  • json_field - the subfield name, per the json_config

A basic CGI script that accepts these parameters and uses them to lookup on a particular subfield is provided.

Properties

name default description
display_as_list undefined
display_as_list_cols undefined
json_config undefined
hidden_fields undefined
readonly_fields undefined
render_table undefined
readonly_fields undefined
table_allow_hide_rows undefined
table_hide_rows_render_js undefined
table_dynamic_row_count undefined
table_hide_table undefined
table_row_count undefined
table_show_hide_rows undefined

Required Phrases

None

Database

Json fields are stored in the database as

fieldname LONGTEXT