Components
Call Form.api.bindevent($('form[role=form]')) so widgets bind.
Upload
Input + .plupload (+ optional .fachoose / preview). Key attrs: data-input-id, data-mimetype, data-multiple, data-preview-id. Cloud storage via storage driver addons.
SelectPage
<input class="form-control selectpage" data-source="category/selectpage" data-field="name">
Editor
Use class="editor" only. Drivers register the implementation — do not hardcode a vendor editor in business code.
Validation
Nice-validator via data-rule. Add novalidate on the form to disable.
Tree select options (Pid / parent)
Use tree_select_options() (in app/common.php) whenever a form needs a hierarchical parent/category dropdown. Same look as system Category / Auth Rule trees.
$rows = Db::name('my_category')->order('weigh desc,id asc')->select()->toArray();
// optional: localize $rows[*]['name'] first
$parentList = tree_select_options($rows, 'name', 'pid', lang('None'), $excludeIds);
$this->view->assign('parentList', $parentList);
<select class="form-control selectpicker" name="row[pid]" data-live-search="true">
{foreach name="parentList" item="vo"}
<option value="{$key}">{$vo|raw}</option>
{/foreach}
</select>
- Labels include Tree spacers (
/ ├ / └) — always output with|raw. - Pass
$excludeIdson edit (self + descendants) so a node cannot nest under itself. - Reference: store Category admin, core
CategoryPid select.
Admin AMD modules (add / edit dialogs)
List “Add/Edit” opens a separate Layer iframe. It does not inherit define('backend/…') from the index page. Defining the module only in index.html makes RequireJS load a missing /assets/js/backend/….js → Script error for "backend/…", and upload/choose stop working.
- Must: every action view (
index/add/edit/ detail…) can load the same AMD define. - Prefer: shared
script.htmlincluded by each action — do not add per-page files underpublic/assets/js/backend/**. - After inserting upload rows dynamically (e.g. SKU), call
Form.events.faupload($form)andForm.events.faselect($form).
{include file="shop/goods/script" /}
Unified upload/choose: build_upload_field()
Prefer build_upload_field() (app/common.php) for admin image/file fields: emits .faupload + .fachoose + preview.
{:build_upload_field('c-image', 'row[image]', (string)($row['image'] ?? ''), ['mode'=>'image'])}
{:build_upload_field('c-images', 'row[images]', (string)($row['images'] ?? ''), ['mode'=>'medias'])}
- Modes:
image|images|file|files|media|medias(media* = image+video) - Use
.faupload/.fachoose(legacy.pluploadstill works) - Page still needs AMD
Form.api.bindeventor buttons do nothing