All pages
Powered by GitBook
1 of 9

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Date & Time

{
    "format" : "%Y-%m-%d"
}

The date & timestamp input field is where you can input a date. In the JSON above you can specify the format value of the output of the date. It allows you to display a formatted date in browse and read views, using Carbon's formatLocalized() method

Formfields

Formfields are the hearth of Voyagers BREAD-system. Each formfield represents a field in your database-table and one input (or output) in BREAD. To tweak your formfields you can insert JSON options which are described in the following pages.

All formfields share a handful options:

Description

All types can include a description in order to help your future self or other users using your Voyager admin panel to understand exactly what a specific BREAD input field is for, this can be defined in the Optional Details JSON input field:

Display options

There are also a few options that you can include to change the way your BREAD is displayed. You can add a display key to your json object and change the width of the particular field and even specify a custom ID.

The width is displayed on a 12-grid system. Setting it with a width of 3 will span 25% of the width.

The id will let you specify a custom id wrapper around your element. example:

Default value

Most formfields allow you to define a default value when adding an entry:

Null Values

You might want to save an input field into the database as a null value instead of an empty string.

Simply enough, inside the BREAD you can include the following Optional Details for the field:

This will turn an empty string into a null value. However you might want to be able to add both an empty string and a null value to the database for that field. However you have to choose a replacement for the null value, but it can be anything you wish. For example, if you want a field to change a string (ex. Nothing) into a null value you could include the following Optional Details for that field:

Now entering Nothing into the field will end up as a null value in the database.

Generating Slugs

Using the bread builder you may wish to automatically generate slugs of a certain input. Lets say you have some posts, which have a title and a slug. If you want to automatically generate the slug from the title attribute, you may include the following Optional Details:

This will automatically generate the slug from the input of the title field. If a slug does already exists, it will only be updated if forceUpdate is set enabled, by default this is disabled.

Custom view

You can specify a custom view to be used for a formfield. To do so, you have to specify the view attribute for your desired field:

This will then load my_view from resources/views instead of the formfield.

You get plenty of data passed to your view for you to use:

  • $view can be browse, read, edit, add or order

  • $content the content for this field

You can also use a custom field view for a specific action (browse, edit, etc) or for similar actions (browse and read). The custom views are:

The same variables as above will be passed to your custom action view.

Developing a custom formfield? If you are developing a custom formfield and want to customize any of the views, you can do so by merging view into $options in your formfields createContent() method.

{
    "description": "A helpful description text here for your future self."
}

$dataType the DataType

  • $dataTypeContent the whole model-instance

  • $row the DataRow

  • $options the DataRow details

  • Dropdown

    {
        "default" : "option1",
        "options" : {
            "option1": "Option 1 Text",
            "option2": "Option 2 Text"
        }
    }

    When specifying that an input type should be a dropdown you will need to specify the values of that dropdown. In the JSON above you can specify the default value of the dropdown if it does not have a value. Additionally, in the options object you will specify the value of the option on the left and the text to be displayed on the right.

    {
        "display": {
            "width": "3",
            "id": "custom_id"
        }
    }
    <div id="custom_id">
        <!-- Your field element -->
    </div>
    {
        "default" : "Default text"
    }
    {
        "null": ""
    }
    {
        "null": "Nothing"
    }
    {
        "slugify": {
            "origin": "title",
            "forceUpdate": true
        }
    }
    {
        "view": "my_view"
    }
    {
        "view_browse": "my_browse_view",
        "view_read": "my_read_view",
        "view_add": "my_add_view",
        "view_edit": "my_edit_view",
        "view_order": "my_order_view"
    }

    Checkbox/Multiple Checkbox/Radio

    Checkbox

    {
        "on" : "On Text",
        "off" : "Off Text",
        "checked" : true
    }

    In Voyager a Checkbox is converted into a toggle switch, and as you can see above the on key will contain the value when the toggle switch is on, and the off will contain the value that is set when the switch is off. If checked is set to true the checkbox will be toggle on; otherwise by default it will be off.

    Multiple Checkbox

    You can create as many checkboxes as you want.

    Radio Button

    The Radio button is exactly the same as the dropdown. You can specify a default if one has not been set and in the options object you will specify the value of the option on the left and the text to be displayed on the right.

    Number

    These are standard attributes for number input field, default value for step is any if not defined.

    {
        "checked" : true,
        "options": {
            "checkbox1": "Checkbox 1 Text",
            "checkbox2": "Checkbox 2 Text"
        }
    }
    {
        "default" : "radio1",
        "options" : {
            "radio1": "Radio Button 1 Text",
            "radio2": "Radio Button 2 Text"
        }
    }
    {
        "step" : 0.1,
        "min" : 0,
        "max" : 10,
        "default": 1,
    }

    TinyMCE

    If you want to customize TinyMCE within Voyager, you can do so by adding a additional JS file to your config.

    In this file you have to define a function like

    function tinymce_init_callback(editor)
    {
        //...
    }

    If you need to manipulate TinyMCE before it was initialized, you can use

    function tinymce_setup_callback(editor)
    {
        //...
    }

    If you want to customize TinyMCE init configuration Options you can merge your custom options in BREAD details as follow:

    {
        "tinymceOptions" : {
            "name": "value"
        }
    }

    If you want to use tinyMCE outside it's default template rich_text_box you'll need initialize it with:

    tinymce.init(window.voyagerTinyMCE.getConfig());

    For all possible variables, functions and configuration Options please refer to the TinyMCE documentation.

    Coordinates

    Optional Details

    Set these in the Edit BREAD interface

    showLatLngInput / showAutocompleteInput

    Set either of these to false to not include that input. Both default to true.

    onChange

    Defines an onChange callback so that you can perform subsequent actions (such as using the Autocomplete Place address to populate another field) after the user changes any of the inputs in this formfield.

    onChange callback is debounced at 300ms.

    First parameter is eventType ("mapDragged", "latLngChanged", or "placeChanged"). Second parameter is data object containing lat, lng, and place properties.

    Images

    The image input has many options. By default if you do not specify any options no problem... Your image will still be uploaded. But, if you want to resize an image, set the quality of the image, or specify thumbnails for the uploaded image you will need to specify those details.

    resize If you want to specify a size you will need to include that in the resize object. If you set either height or width to null it will keep the aspect ratio based on the width or height that is set. So, for the example above the width is set to 1000 pixels and since the height is set to null it will resize the image width to 1000 pixels and resize the height based on the current aspect ratio.

    quality If you wish to compress the image with a percentage quality you can specify that percentage in the quality

    {
      "showAutocompleteInput": false,
      "showLatLngInput": false
    }
    {
      "onChange": "myFunction"
    }
    key. Typically between 70 and 100% there is little notice of image quality, but the image size may be dramatically lower.

    upsize This is only valid if you have set your image to be resized. If you specify your image to resized to 1000 pixels and the image is smaller than 1000 pixels by default it will not upsize that image to the 1000 pixels; however, if you set upsize to true. It will upsize all images to your specified resize values.

    thumbnails Thumbnails takes an array of objects. Each object is a new thumbnail that is created. Each object contains 2 values, the name and scale percentage. The name will be attached to your thumbnail image (as an example say the image you uploaded was ABC.jpg a thumbnail with the name of medium would now be created at ABC-medium.jpg). The scale is the percentage amount you want that thumbnail to scale. This value will be a percentage of the resize width and height if specified.

    {
        "resize": {
            "width": "1000",
            "height": null
        },
        "quality" : "70%",
        "upsize" : true,
        "thumbnails": [
            {
                "name": "medium",
                "scale": "50%"
            },
            {
                "name": "small",
                "scale": "25%"
            },
            {
                "name": "cropped",
                "crop": {
                    "width": "300",
                    "height": "250"
                }
            }
        ]
    }
    function myFunction(eventType, data) {
      console.log('eventType', eventType);
      console.log('data.lat', data.lat);
      console.log('data.lng', data.lng);
      console.log('data.place', data.place);
    }

    Media Picker

    The media picker formfield allows you to upload/delete/select files directly from the media-manager. You can customize the behaviour with the following options:

    Name
    Description
    Type
    Default

    base_path

    The start path relative to the filesystem

    String

    /bread-slug/

    rename

    Allowed types

    If you want your users to only be able to upload specific file-types you can do so by passing an object with mime-types to the `allowed` prop, for example:

    or

    Expressions

    The base_path and rename can contain the following placeholders:

    • {pk} the primary-key of the entry (only for base_path)

    • {uid} the user-id of the current logged-in user

    • {date:format} the current date in the format defined in format

    So a base_path can, for example, look like the following:

    Watermark

    A watermark can be added to uploaded images. To do so, you need to define a source property relative to Voyagers storage-disk. There are a few optional arguments you can use: position the position where the watermark is placed. Can be:

    • top-left (default)

    • top

    • top-right

    • left

    x Relative offset to the position on the x-axis. Defaults to 0

    y Relative offset to the position on the y-axis. Defaults to 0

    size the size (in percent) of the watermark relative to the image. Defaults to 15

    Thumbnails

    You can generate thumbnails for each uploaded image. A thumbnail can be one of three types:

    Fit

    Fit combines cropping and resizing to find the best way to generate a thumbnail matching your dimensions. You have to pass width and can pass height and position. An example for fit would be:

    Crop

    Crop an image by given dimensions and position. You have to pass width and height and can pass x and y. An example for crop would be:

    Resize

    Resize the image to the given dimensions. You have to pass width and/or height. Some examples for resize:

    A watermark can also be inserted into each thumbnail. Just define the on the parent and set watermark to true for each thumbnail you want to insert the watermark to.

    {
        "max": 10,
        "min": 0,
        "expanded": true,
        "show_folders": true,
        "show_toolbar": true,
        "allow_upload": true,
        "allow_move": true,
        "allow_delete": true,
        "allow_create_folder": true,
        "allow_rename": true,
        "allow_crop": true,
        "allowed": [],
        "hide_thumbnails": false,
        "quality": 90,
        "watermark": {
            "source": "...",
            "position": "top-left",
            "x": 0,
            "y": 0
        }
    }
    . For example
    {date:d.m.Y}
  • {random:10} random string with N characters

  • center

  • right

  • bottom-left

  • bottom

  • bottom-right

  • Rename uploaded files to a given string/expression

    String

    Original name

    delete_files

    Delete files if the BREAD entry is deleted.

    Use with caution!

    bool

    false

    show_as_images

    Shows stored data as images when browsing

    bool

    false

    min

    The minimum amount of files that can be selected

    int

    0

    max

    The maximum amount of files that can be selected.

    0 means infinite

    int

    0

    expanded

    If the media-picker should be expanded by default

    bool

    true

    show_folders

    Show subfolders

    bool

    true

    show_toolbar

    Shows/hides the whole toolbar

    bool

    false

    allow_upload

    Allow users to upload new files

    bool

    true

    allow_move

    Allow users to move files/folders

    bool

    true

    allow_delete

    Allow users to delete files

    bool

    true

    allow_create_folder

    Allow users to create new folders

    bool

    true

    allow_rename

    Allow users to rename files.

    Use with caution!

    bool

    true

    allow_crop

    Allow users to crop images

    bool

    true

    hide_thumbnails

    Hides known thumbnails and shows them as children of the parent image

    bool

    true

    quality

    Sets the quality of uploaded images and thumbnails

    int

    90

    allowed

    The allowed types to be uploaded/selected.

    Empty object means all types.

    Files with other types won't be displayed.

    Object

    []

    watermark-options
    ["image", "audio", "video"]
    ["image/jpeg", "image/png", "image/bmp"]
    {
        "base_path": "/my-bread/{pk}/{date:Y}/{date:m}/"
    }
    {
        "thumbnails": [
            {
                "type": "fit",
                "name": "fit-500",
                "width": 500, // Required
                "height": 500, // Optional
                "position": "center" // Optional. Refer to http://image.intervention.io/api/fit
            }
        ]
    }
    {
        "thumbnails": [
            {
                "type": "crop",
                "name": "crop-500-500",
                "width": 500, // Required
                "height": 500, // Required
                "x": 50, // Optional. Left offset
                "y": 50, // Optional. Top offset
            }
        ]
    }
    {
        "thumbnails": [
            // Width will be 500px, height will be calculated based on the aspect-ratio
            {
                "type": "resize",
                "name": "resize-500",
                "width": 500,
                "upsize": true, // Optional. Set to false to prevent upsizing
            },
            // Resizes the image to 500x500px
            {
                "type": "resize",
                "name": "resize-500-500",
                "width": 500,
                "height": 500
            },
            // Height will be 500px, width will be auto-calculated
            {
                "type": "resize",
                "name": "resize-500",
                "width": null,
                "height": 500
            }
        ]
    }