此網站需要開啟JavaScript
JavaScript is required

表單欄位

CommonFormField 負責 label 與錯誤訊息,CommonFormControl 負責輸入本身。兩者搭配使用,不要各自單獨用。

欄位容器

CommonFormField

components/Common/Form/Field.vue

把 label、必填標記、錯誤訊息集中在這一層, 裡面放什麼控制項都可以。錯誤訊息同時傳給 Field 與 Control —— 前者負責顯示文字,後者負責把邊框變成錯誤色。

搭配 Control 使用

Props

名稱型別預設值說明
labelString''欄位標籤
requiredBooleanfalse在 label 旁顯示必填標記
labelForString''對應內層控制項的 id
helpString''欄位下方的輔助說明
errorString''錯誤訊息,有值就會顯示
disabledBooleanfalse
noLabelBooleanfalse不畫 label,但保留間距
type'input' | 'options''input'options 用在一整組選擇項,間距與對齊不同

Slots

SlotSlot props說明
default—放輸入控制項
nextToLabel—label 右側,放說明圖示之類
labelSide—label 同一列的最右側

輸入控制項

CommonFormControl

components/Common/Form/Control.vue

全站的輸入框都走這一個元件,用 type 切換行為。 兩種下拉的差別:select 是客製化選單 (含 floating-ui 轉向偵測,樣式可控), ogSelect 是原生 <select> 改外觀 (行動裝置上會叫出系統選單,體驗較好)。

文字輸入

密碼(可切換明碼)

錯誤狀態

請輸入正確的 Email 格式

Props

名稱型別預設值說明
modelValueString | Number''用 v-model 綁定
name*String''表單欄位名稱
idString''搭配 CommonFormField 的 labelFor
type'text' | 'textarea' | 'select' | 'ogSelect' | 'email' | 'password' | 'date' | 'tel' | 'number' | 'url''text'select 是客製化下拉(含 floating-ui 轉向偵測),ogSelect 是原生 select 改外觀
optionsArray<{ label, value }>[]select / ogSelect 用
placeholderString''
iconString''欄位內的圖示
requiredBooleanfalse
disabledBooleanfalse
errorString''
maxlengthString | Numbernull
autocompleteString''
inputmodeString''手機鍵盤類型,數字欄位建議傳 numeric
borderlessBooleanfalse
transparentBooleanfalse
ctrlKFocusBooleanfalse支援 Cmd/Ctrl + K 聚焦
noHidePasswordIconBooleanfalsepassword 類型時不顯示切換明碼的眼睛

* 為必填

Events

事件Payload說明
update:modelValueString | Number搭配 v-model
changeEvent值改變時觸發,用來連動其他欄位
on-blur—失焦,通常用來觸發驗證
setRefHTMLElement把內層 input 的 ref 傳出去

多行輸入

CommonFormTextArea

components/Common/Form/TextArea.vue

傳 maxlength 時會自動顯示字數計數。

含字數上限

Props

名稱型別預設值說明
modelValueString''
name*String''
idString''
placeholderString''
maxlengthString | Numbernull有值時會顯示字數計數
disabledBooleanfalse
errorString''

* 為必填

Events

事件Payload說明
update:modelValueString
onBlur—