> For the complete documentation index, see [llms.txt](https://bpio.gitbook.io/piman/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bpio.gitbook.io/piman/vue2/form.md).

# Form

<div data-full-width="false"><figure><img src="/files/lFYobrZjFnDrzMD9At7M" alt="Form 介紹示意圖"><figcaption></figcaption></figure></div>

Dropdown 下拉式選單，用在讓使用者針對選取的資料採取下一步互動。點擊按鈕會出現一個懸浮區域，裡面是一系列的選項，外觀與 Select 相似，但與 Select 最大的不同之處在於 Dropdown 點擊選項後觸發選項事件，並且關閉懸浮區域。

### 範例 <a href="#example" id="example"></a>

```html
<bpa-form
  :model="exampleForm"
  ref="refExampleForm"
  :rules="exampleRules"
>
  <bpa-form-item
    label="姓名"
    prop="name"
    required
    labelFor="thisIDIsMustTheSame"
    @validate="onValidate"
  >
    <bpa-input
      v-model="exampleForm.name"
      id="thisIDIsMustTheSame"
    />
  </bpa-form-item>
</bpa-form>
```

```javascript
data() {
  return {
    exampleRules: {
      name: [
        { required: true, message: 'name is required' },
        { min: 3, max: 5, message: 'at least 3 to 5 words', trigger: 'change' }
      ]
    }
  }
}
```

### 驗證 <a href="#validation" id="validation"></a>

```javascript
// required
const rules = {
  input:[{ required: true, message: '此欄位必填', trigger: 'blur' }]
}

// multiple
const rules = {
  check:[{ required: true, type:'array', message: 'please check', trigger: 'change' }]
}

// multiple
const rules = {
  check:[{ required: true, type:'array', message: 'please check', trigger: 'change' }]
}

// max and min
const rules = {
  check:[{ min:0, max: 3, type:'array', message: 'please check(max 3)', trigger: 'change' }]
}

// password
const form = {
   password:'',
   confirm:''
 }
 const validatePsw = (rule: Array<any>, value: string, callback: (par?: any)=>{}) => {
   if (value !== form.password) {
     let msg = 'Not Match!'
     callback(new Error(msg));
   } else {
     callback();
   }
 }
 const rules = {
   confirm:[
     { required: true, validator: validatePsw, trigger:'blur'}
   ],
 }

// regular express
const rules = {
   password:[
     { 
       pattern: /(?=.{12,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W_])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])).*/,  
       trigger: 'blur' 
     }
   ],
 }ja
```

### Fieldset

```html
<fieldset class="bpa-fieldset">
  <legend>Experience</legend>
  <div class="bpa-fieldset-container">
    <bpa-form-item
      label="Company"
      prop="company"
      labelFor="testModelId2"
     >
      <bpa-input
         v-model="exampleForm.company"
         id="testModelId2"
      />
    </bpa-form-item>
  </div>
</fieldset>
```

### bpa-form 屬性 <a href="#bpa-form-props" id="bpa-form-props"></a>

<table data-full-width="false"><thead><tr><th width="127">Name</th><th>Value</th><th>Type</th><th>Default</th><th data-type="checkbox">Required</th><th>Note</th></tr></thead><tbody><tr><td>model</td><td></td><td>Object</td><td>random</td><td>false</td><td></td></tr><tr><td>rules</td><td></td><td>Object<br>(<a href="https://github.com/yiminghe/async-validator">async-validator</a>)</td><td></td><td>false</td><td></td></tr><tr><td>autofocus</td><td></td><td>Boolean</td><td>true</td><td>false</td><td>自動聚焦</td></tr></tbody></table>

### bpa-form 方法 <a href="#bpa-form-methods" id="bpa-form-methods"></a>

<table data-full-width="false"><thead><tr><th width="121">Name</th><th>Parameters</th></tr></thead><tbody><tr><td>validate</td><td>Function () : Promise({valid: booleaml; error: object})</td></tr></tbody></table>

### bpa-form-item 屬性 <a href="#bpa-form-item-props" id="bpa-form-item-props"></a>

<table data-full-width="false"><thead><tr><th width="127">Name</th><th width="77">Value</th><th width="146">Type</th><th>Default</th><th data-type="checkbox">Required</th><th>Note</th></tr></thead><tbody><tr><td>prop</td><td></td><td>String</td><td></td><td>false</td><td></td></tr><tr><td>label</td><td></td><td>String</td><td></td><td>true</td><td></td></tr><tr><td>labelFor</td><td></td><td>String</td><td></td><td>false</td><td></td></tr><tr><td>required</td><td></td><td>Boolean</td><td></td><td>false</td><td></td></tr><tr><td>error</td><td></td><td>Boolean</td><td></td><td>false</td><td></td></tr><tr><td>hint</td><td></td><td>String</td><td></td><td>false</td><td></td></tr><tr><td>rules</td><td></td><td>[Object,  Array]</td><td></td><td>false</td><td></td></tr><tr><td>model</td><td></td><td>[Object, Array, Boolean, String, Number]</td><td></td><td>false</td><td></td></tr></tbody></table>

### bpa-form-item 方法 <a href="#bpa-form-item-methods" id="bpa-form-item-methods"></a>

<table data-full-width="false"><thead><tr><th>Name</th><th>Parameters</th><th>Note</th></tr></thead><tbody><tr><td>validate</td><td>{ valid: boolean, message: string }</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### Demo

{% embed url="<https://codesandbox.io/embed/piman-form-klm4on?fontsize=14&module=/src/App.vue&theme=dark>" fullWidth="false" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bpio.gitbook.io/piman/vue2/form.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
