Jump to content

Url field: Difference between revisions

From EPrints Documentation
mNo edit summary
mNo edit summary
 
Line 14: Line 14:
**** [[Url field]]
**** [[Url field]]


== Properties ==
== Additional Properties ==
As for [[Id field]]s.
As for [[Id field#Additional Properties|Id fields]].


== Required Phrases ==
== Required Phrases ==
No additional phrases beyond those required for [[Id field]]s.
No additional phrases beyond those required for [[Id field#Required Phrases|Id fields]].


== Database ==
== Database ==

Latest revision as of 23:21, 9 April 2023


Description[edit]

This field works just like a Id field except that:

  • It gives a validation error if it does not appear to be a valid URL.
  • When rendered it is rendered as a link to the URL (unless the render_dont_link property is set).

Also, as URLs are liable to be more that 256 characters this field is stored as a LONGTEXT field in the database.

Inheritance[edit]

Additional Properties[edit]

As for Id fields.

Required Phrases[edit]

No additional phrases beyond those required for Id fields.

Database[edit]

Url fields are stored in the database as

fieldname LONGTEXT

API[edit]

See API page.

Examples[edit]

Most basic example.

 { 
    name => 'url', 
    type => 'url',
 }

Use a bespoke render function to truncate the URL at the end if it is too long.

{
    name => 'official_url',
    type => 'url',
    render_value => 'EPrints::Extras::render_url_truncate_end',
}

Use Url field as a sub-field in a multiple Compound field. Limiting the width of its input field.

{
    name => 'related_url',
    type => 'compound',
    multiple => 1,
    render_value => 'EPrints::Extras::render_related_url',
    fields => [
        {
            sub_name => 'url',
            type => 'url',
            input_cols => 40,
        },
        {
            sub_name => 'type',
            type => 'set',
            options => [qw(
                pub
                author
                org
            )],
        }
    ],
    input_boxes => 1,
    input_ordered => 0,
}