Boolean field: Difference between revisions
Reinstate link to API page even though a redirect |
|||
| (16 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
{{fieldtypes}} | |||
== Description == | == Description == | ||
Describes a simple yes/no value. Unless the field has the ''required'' property set, it can actually have a third setting of unset. This can be useful as it distinguishes between a "False" and a "don't know/haven't filled this in yet". For example when asking if a paper is refereed, this is a boolean field. However it's not required as often someone isn't sure, and does not want to click "no" when that's not necessarily true. | Describes a simple yes/no value. Unless the field has the ''required'' property set, it can actually have a third setting of unset. This can be useful as it distinguishes between a "False" and a "don't know/haven't filled this in yet". For example when asking if a paper is refereed, this is a boolean field. However it's not required as often someone isn't sure, and does not want to click "no" when that's not necessarily true. | ||
== | == Inheritance == | ||
* [[Metadata]] | |||
** [[Boolean field]] | |||
== Additional Properties == | |||
{| border="1" cellpadding="3" cellspacing="0" | {| border="1" cellpadding="3" cellspacing="0" | ||
| | ! Name !! Default Value !! Required !! Description !! Notes | ||
|- | |||
| '''input_style''' || <tt>checkbox</tt> || NO || This controls how the field is rendered in input forms. May be one of <tt>menu</tt>, <tt>radio</tt> or <tt>checkbox</tt>. || | |||
|- | |||
| '''input_rows''' || n/a || NO || Number of rows for select box in input form. || Only applicable if <tt>input_style => 'menu'</tt>. If so, must be configured within field definition. | |||
|- | |||
| '''false_first''' || <tt>0</tt> || NO || Whether the false option should appear before the true option. || | |||
|- | |- | ||
|} | |} | ||
== Required Phrases == | == Required Phrases == | ||
In addition to the [[Metadata#Required_Phrases|standard metadata field phrases]]: | |||
=== menu style === | === menu style === | ||
| Line 36: | Line 37: | ||
<epp:phrase id="eprint_fieldopt_myboolean_TRUE">Certainly!</epp:phrase> | <epp:phrase id="eprint_fieldopt_myboolean_TRUE">Certainly!</epp:phrase> | ||
<epp:phrase id="eprint_fieldopt_myboolean_FALSE">No way!</epp:phrase> | <epp:phrase id="eprint_fieldopt_myboolean_FALSE">No way!</epp:phrase> | ||
==== optional phrase to replace 'UNSPECIFIED' text ==== | |||
To overwrite the default 'UNSPECIFIED' option displayed when a boolean field is not required, a phrase with an underscore at the end can be used: | |||
''datasetid'' + "_fieldopt_" + ''fieldname'' + "_" | |||
Example: | |||
<epp:phrase id="eprint_fieldopt_myboolean_">Don't know.</epp:phrase> | |||
=== radio style === | === radio style === | ||
| Line 49: | Line 59: | ||
<epp:phrase id="eprint_radio_myboolean"><label><epc:pin name="true"/>Yes, I like cheese.</label><br/><label><epc:pin name="false"/>No, cheese is bad.</label></epp:phrase> | <epp:phrase id="eprint_radio_myboolean"><label><epc:pin name="true"/>Yes, I like cheese.</label><br/><label><epc:pin name="false"/>No, cheese is bad.</label></epp:phrase> | ||
== Database == | |||
Boolean fields are stored in the database as | |||
fieldname VARCHAR(5) | |||
== | == API == | ||
See [[API:EPrints/MetaField/Boolean|API page]]. | |||
In the code these fields are stored as strings containing <tt>TRUE</tt>, <tt>FALSE</tt> or <tt>undef</tt> if they are not set. | |||
== Examples == | |||
Most basic example. Display a checkbox as this is the default. | |||
{ | |||
name => "no_request_email_button", | |||
type => "boolean", | |||
} | |||
Display as radio group of options. Allows <tt>TRUE</tt>, <tt>FALSE</tt> and <tt>UNSPECIFIED</tt> but phrases uses will determine labelling of options displaye. | |||
{ | |||
name => 'refereed', | |||
type => 'boolean', | |||
input_style => 'radio', | |||
}, | |||
Display as drop down list of options. Allows only <tt>TRUE</tt> or <tt>FALSE</tt> as <tt>required</tt> is set to true. | |||
{ | |||
name => 'is_artwork', | |||
type => 'boolean', | |||
required => 1, | |||
input_style => 'menu', | |||
}, | |||
Latest revision as of 09:47, 9 July 2024
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
Description[edit]
Describes a simple yes/no value. Unless the field has the required property set, it can actually have a third setting of unset. This can be useful as it distinguishes between a "False" and a "don't know/haven't filled this in yet". For example when asking if a paper is refereed, this is a boolean field. However it's not required as often someone isn't sure, and does not want to click "no" when that's not necessarily true.
Inheritance[edit]
Additional Properties[edit]
| Name | Default Value | Required | Description | Notes |
|---|---|---|---|---|
| input_style | checkbox | NO | This controls how the field is rendered in input forms. May be one of menu, radio or checkbox. | |
| input_rows | n/a | NO | Number of rows for select box in input form. | Only applicable if input_style => 'menu'. If so, must be configured within field definition. |
| false_first | 0 | NO | Whether the false option should appear before the true option. |
Required Phrases[edit]
In addition to the standard metadata field phrases:
[edit]
If you use input_style=>"menu" then you need two phrases of the type:
datasetid + "_fieldopt_" + fieldname + "_TRUE" datasetid + "_fieldopt_" + fieldname + "_FALSE"
These control the display of the items in the menu.
Example:
<epp:phrase id="eprint_fieldopt_myboolean_TRUE">Certainly!</epp:phrase> <epp:phrase id="eprint_fieldopt_myboolean_FALSE">No way!</epp:phrase>
optional phrase to replace 'UNSPECIFIED' text[edit]
To overwrite the default 'UNSPECIFIED' option displayed when a boolean field is not required, a phrase with an underscore at the end can be used:
datasetid + "_fieldopt_" + fieldname + "_"
Example:
<epp:phrase id="eprint_fieldopt_myboolean_">Don't know.</epp:phrase>
radio style[edit]
This uses a single phrase with two pins in it to indicate the locations of the radio buttons. The phrase id is:
datasetid + "_radio_" + fieldname
We suggest placing a <label> element around the radio button and it's title - as well as being good practice, this also means that in some browsers clicking on the text will select the button.
For example:
<epp:phrase id="eprint_radio_myboolean"><label><epc:pin name="true"/>Yes, I like cheese.</label>
<label><epc:pin name="false"/>No, cheese is bad.</label></epp:phrase>
Database[edit]
Boolean fields are stored in the database as
fieldname VARCHAR(5)
API[edit]
See API page.
In the code these fields are stored as strings containing TRUE, FALSE or undef if they are not set.
Examples[edit]
Most basic example. Display a checkbox as this is the default.
{
name => "no_request_email_button",
type => "boolean",
}
Display as radio group of options. Allows TRUE, FALSE and UNSPECIFIED but phrases uses will determine labelling of options displaye.
{
name => 'refereed',
type => 'boolean',
input_style => 'radio',
},
Display as drop down list of options. Allows only TRUE or FALSE as required is set to true.
{
name => 'is_artwork',
type => 'boolean',
required => 1,
input_style => 'menu',
},