OctoberCms Forms
来源:互联网 发布:ubuntu 启动过程 黑屏 编辑:程序博客网 时间:2024/06/05 15:24
Form fields are defined with the YAML file. The form fields configuration is used by the form behavior for creating the form controls and binding them to the model fields. The file is placed to a subdirectory of the models directory of a plugin. The subdirectory name matches the model class name written in lowercase. The file name doesn't matter, but fields.yaml and form_fields.yaml are common names. Example form fields file location:
plugins/ acme/ blog/ models/ <=== Plugin models directory post/ <=== Model configuration directory fields.yaml <=== Model form fields config file Post.php <=== model class
Fields can be placed in three areas, the outside area, primary tabs or secondary tabs. The next example shows the typical contents of a form fields definition file.
# ===================================# Form Field Definitions# ===================================
fields:
blog_title:
label: Blog Title
description: The title for this blog
published_at:
label: Published date
description: When this blog post was published
type: datepicker
[...]
tabs:
fields:
[...]
secondaryTabs:
fields:
tabs
and secondaryTabs
, you can specify these options:对于每一个tab 定义,命名tabs和secondaryTabsFor each field you can specify these options (where applicable):
@
symbol in the field name, for example, name@update
.dependsOnan array of other field names this field depends on, when the other fields are modified, this field will update.triggerspecify conditions for this field using trigger events.presetallows the field value to be initially set by the value of another field, converted using theinput preset converter.requiredplaces a red asterisk next to the field label to indicate it is required.attributesspecify custom HTML attributes to add to the form field element.containerAttributesspecify custom HTML attributes to add to the form field container.There are various native field types that can be used for the type setting. For more advanced form fields, a form widget can be used instead.
- Text
- Number
- Password
- Textarea
- Dropdown
- Radio List
- Checkbox
- Checkbox List
- Switch
- Section
Text
text
- renders a single line text box. This is the default type used if none is specified.blog_title: label: Blog Title type: text
Number
number
- renders a single line text box that takes numbers only.your_age: label: Your Age type: number
Password
password
- renders a single line password field.user_password: label: Password type: password
Textarea
textarea
- renders a multiline text box. A size can also be specified with possible values: tiny, small, large, huge, giant.blog_contents: label: Contents type: textarea size: large
Dropdown
dropdown
- renders a dropdown with specified options. There are 4 ways to provide the drop-down options. The first method definesoptions
directly in the YAML file:status: label: Blog Post Status type: dropdown options: draft: Draft published: Published archived: Archived
The second method defines options with a method declared in the model's class. If the options element is omitted, the framework expects a method with the name
get*Field*Options()
to be defined in the model. Using the example above, the model should have thegetStatusOptions()
method. This method takes a single parameter, the current key value, and should return an array of options in the format key => label.status: label: Blog Post Status type: dropdown
Supplying the dropdown options tn the model class:
public function getStatusOptions($keyValue = null){ return ['all' => 'All', ...];}
The third global method
getDropdownOptions()
can also be defined in the model, this will be used for all dropdown field types for the model. This method takes two parameters, the field name and current key value, and should return an array of options in the format key => label.public function getDropdownOptions($fieldName = null, $keyValue = null){ if ($fieldName == 'status') return ['all' => 'All', ...]; else return ['' => '-- none --'];}
The fourth method uses a specific method declared in the model's class. In the next example the
listStatuses()
method should be defined in the model class. This method takes two parameters, the current key value and field name, and should return an array of options in the format key => label.status: label: Blog Post Status type: dropdown options: listStatuses
Supplying the dropdown options to the model class:
public function listStatuses($keyValue = null, $fieldName = null){ return ['published' => 'Published', ...];}
By default the dropdown has a searching feature, allowing quick selection of a value. This can be disabled by setting the
showSearch
option tofalse
.status: label: Blog Post Status type: dropdown showSearch: false
Radio List
radio
- renders a list of radio options, where only one item can be selected at a time.security_level: label: Access Level type: radio options: all: All registered: Registered only guests: Guests only
Radio lists can also support a secondary description.
security_level: label: Access Level type: radio options: all: [All, Guests and customers will be able to access this page.] registered: [Registered only, Only logged in member will be able to access this page.] guests: [Guests only, Only guest users will be able to access this page.]
Radio lists support three ways of defining the options, exactly like the dropdown field type. For radio lists the method could return either the simple array: key => value or an array of arrays for providing the descriptions: key => [label, description]
Checkbox
checkbox
- renders a single checkbox.show_content: label: Display content type: checkbox default: true
Checkbox List
checkboxlist
- renders a list of checkboxes.permissions: label: Permissions type: checkboxlist options: open_account: Open account close_account: Close account modify_account: Modify account
Checkbox lists support three ways of defining the options, exactly like the dropdown field type and also support secondary descriptions, found in the radio field type.
Switch
switch
- renders a switchbox.show_content: label: Display content type: switch comment: Flick this switch to display content
Section
section
- renders a section heading and subheading. Thelabel
andcomment
values are optional and contain the content for the heading and subheading.user_details_section: label: User details type: section comment: This section contains details about the user.
Partial
partial
- renders a partial, thepath
value can refer to a partial view file otherwise the field name is used as the partial name. Inside the partial these variables are available:$value
is the default field value,$model
is the model used for the field and$field
is the configured class objectBackend\Classes\FormField
.content: type: partial path: $/acme/blog/models/comments/_content_field.htm
Hint
hint
- identical to apartial
field but renders inside a hint container that can be hidden by the user.content: type: hint path: content_field
Widget
widget
- renders a custom form widget, thetype
field can refer directly to the class name of the widget or the registered alias name.blog_content: type: Backend\FormWidgets\RichEditor size: huge
Form widgets
There are various form widgets included as standard, although it is common for plugins to provide their own custom form widgets. You can read more on the Form Widgets article.
- Code editor
- Color picker
- Date picker
- File upload
- Record finder
- Media finder
- Relation
- Repeater
- Rich editor / WYSIWYG
- Markdown editor
- Tag list
Code editor
codeeditor
- renders a plaintext editor for formatted code or markup. Note the options may be inherited by the code editor preferences defined for the Administrator in the back-end.css_content: type: codeeditor size: huge language: html
Option Description languagecode language, for example, php, css, js, html. Default: php.showGuttershows a gutter with line numbers. Default: true.wrapWordsbreaks long lines on to a new line. Default true.fontSizethe text font size. Default: 12.Color picker
colorpicker
- renders controls to select a hexadecimal color value.color: label: Background type: colorpicker
Option Description availableColorslist of available colors.Date picker
datepicker
- renders a text field used for selecting date and times.published_at: label: Published type: datepicker mode: date
Option Description modethe expected result, either date, datetime or time. Default: datetime.minDatethe minimum/earliest date that can be selected. Default: 2000-01-01.maxDatethe maximum/latest date that can be selected. Default: 2020-12-31.File upload
fileupload
- renders a file uploader for images or regular files. The field name must use an attachOne or attachMany relation.avatar: label: Avatar type: fileupload mode: image imageHeight: 260 imageWidth: 260
Option Description modethe expected file type, either file or image. Default: file.imageWidthif using image type, the image will be resized to this width, optional.imageHeightif using image type, the image will be resized to this height, optional.fileTypesfile extensions that are accepted by the uploader, optional. Eg:zip,txt
mimeTypesMIME types that are accepted by the uploader, either as file extension or fully qualified name, optional. Eg:bin,txt
useCaptionallows a title and description to be set for the file. Default: trueprompttext to display for the upload button, applies to files only, optional.Record finder
recordfinder
- renders a field with details of a related record. Expanding the field displays a popup list to search large amounts of records. Supported by singular relationships only.user: label: User type: recordfinder list: $/rainlab/user/models/user/columns.yaml prompt: Click the %s button to find a user nameFrom: name descriptionFrom: email
Option Description nameFromthe column name to use in the relation used for displaying the name. Default: name.descriptionFromthe column name to use in the relation used for displaying a description. Default: description.titletext to display in the title section of the popup.prompttext to display when there is no record selected. The%s
character represents the search icon.lista configuration array or reference to a list column definition file, see list columns.recordsPerPagerecords to display per page, use 0 for no pages. Default: 10conditionsspecifies a raw where query statement to apply to the list model query.scopespecifies a query scope method defined in the related form model to apply to the list query always.searchModedefines the search strategy to either contain all words, any word or exact phrase. Supported options: all, any, exact. Default: all.searchScopespecifies a query scope method defined in the related form model to apply to the search query, the first argument will contain the search term.Media finder
mediafinder
- renders a field for selecting an item from the media manager library. Expanding the field displays the media manager to locate a file. The resulting selection is a string as the relative path to the file.background_image: label: Background image type: mediafinder mode: image
Option Description modethe expected file type, either file or image. Default: file.prompttext to display when there is no item selected. The%s
character represents the media manager icon.Relation
relation
- renders either a dropdown or checkbox list according to the field relation type. Singular relationships display a dropdown, multiple relationships display a checkbox list. The label used for displaying each relation is sourced by thenameFrom
orselect
definition.categories: label: Categories type: relation nameFrom: title
Alternatively, you may populate the label using a custom
select
statement. Any valid SQL statement works here.user: label: User type: relation select: concat(first_name, ' ', last_name)
Option Description nameFroma model attribute name used for displaying the relation label. Default: name.selecta custom SQL select statement to use for the name.descriptionFromthe column name to use in the relation used for displaying a description (optional). Default: description.emptyOptiontext to display when there is no available selections.Repeater
repeater
- renders a repeating set of form fields defined within.extra_information: type: repeater form: fields: added_at: label: Date added type: datepicker details: label: Details type: textarea
Option Description forma reference to form field definition file, see backend form fields. Inline fields can also be used.prompttext to display for the create button. Default: Add new item.Rich editor / WYSIWYG
richeditor
- renders a visual editor for rich formatted text, also known as a WYSIWYG editor.html_content: type: richeditor toolbarButtons: bold|italic size: huge
Option Description toolbarButtonswhich buttons to show on the editor toolbar. Default:paragraphFormat|paragraphStyle|quote|bold|italic|align|formatOL|formatUL|insertTable|insertLink|insertImage|insertVideo|insertAudio|insertFile|insertHR|fullscreen|html
The available toolbar buttons are:
fullscreen, bold, italic, underline, strikeThrough, subscript, superscript, fontFamily, fontSize, |, color, emoticons, inlineStyle, paragraphStyle, |, paragraphFormat, align, formatOL, formatUL, outdent, indent, quote, insertHR, -, insertLink, insertImage, insertVideo, insertAudio, insertFile, insertTable, undo, redo, clearFormatting, selectAll, html
Note:
|
will insert a vertical separator line in the toolbar and-
a horizontal one.Markdown editor
markdown
- renders a basic editor for markdown formatted text.md_content: type: markdown size: huge mode: split
Option Description modethe expected view mode, either tab or split. Default: tab.Tag list
taglist
- renders a field for inputting a list of tags.tags: type: taglist separator: space
A tag list can support three ways of defining the
options
, exactly like the dropdown field type.tags: type: taglist options: - Red - Blue - Orange
You may use the
mode
called relation where the field name is a many-to-many relationship. This will automatically source and assign tags via the relationship. If custom tags are supported, they will be created before assignment.tags: type: taglist mode: relation
Option Description modecontrols how the value is returned, either string, array or relation. Default: string.separatorseparate tags with the specified character, either comma or space. Default: comma.customTagsallows custom tags to be entered manually by the user. Default: trueoptionsspecifies a method or array for predefined options. Set to true to use modelget*Field*Options()
method. Optional.nameFromif relation mode is used, a model attribute name for displaying the tag name. Default: name.
- OctoberCms Forms
- OctoberCms 后端用户权限的设置
- forms
- Introducing OctoberCMS系统——一个基于Laravel-based CMS
- document.forms
- Lookup forms
- forms认证
- forms认证
- forms身份验证
- forms 验证
- Forms 验证
- Forms 手电筒
- Web Forms
- Forms身份验证
- Forms验证
- Forms验证
- Forms 身份验证
- SAPscript Forms
- 进阶项目6.1-两人生日差
- HDU 5755 Gambler Bo
- Java之类的继承
- 浅谈.NET应用程序SQL注入
- hdoj4004The Frog's Games
- OctoberCms Forms
- 运动的八卦图
- Programmer error or hard
- leetcode Design Hit Counter
- Question( category_id 关联 category_name)
- 【priority_queue<int,vector<int>,greater<int>>优先队列 按照由小到大顺序】
- The Relationship types
- sh 执行hive 查询 [文件名 要看全] -1
- 学习日常的记录