sidebarDepth: 3

API

Get API $f

  • Global method

    1. $f = formCreate.create(rules)
    2. $f = vm.$formCreate(rules)
  • Component pattern

    1. <form-create v-model="fApi"></form-create>
    1. new Vue({
    2. data(){
    3. return {
    4. fApi:{} //fApi is equivalent to $f
    5. }
    6. }
    7. })

Attributes

Form generation rules

  • Type: array

  • Usage

  1. $f.rule

Global configuration of the form

  • Type: object

  • Usage

  1. $f.config

Field operations

Get all field names of a form

  • Return value: string[]

  • Usage

    1. const fields = $f.fields();

Get key-value pairs of a form

  • Return value: object

  • Usage

    1. const formData = $f.formData()

Get the value of the specified field

  • Parameter{string} field

  • Usage

    1. const value = $f.getValue(field)

    Get the value of the field component

Set the value of a field

  • Sets the value of the specified field

    • Parameter

      • {string} field
      • {any} value
    • Usage

      1. $f.setValue(field,value)

      Change the value of the field component tovalue

  • Batch settings

    • Parameter

      • {object} formData
    • Usage

      1. $f.setValue({
      2. field1:value1,
      3. field2:value2,
      4. field3:value3
      5. });

      Modify the values ​​of field1, field2, field3 components tovalue1, value2, value3 respectively

    Alias ​​methodchangeValue,changeField

Delete specified field

  • Parameter{string} [field|name]

  • Return value{object} rule

  • Usage

    1. $f.removeField(field)

    Delete the field

Get form key-value pairs for two-way data binding

  • Return value{object}

  • Usage

    1. const formData = $f.bind()

Component operation

Update component rules

  • Parameter

    • {string} [field|name]
    • {object} rule
    • {bool} cover The default is deep copy, which is directly overridden when equal to true
  • Return value{object} rule

  • Usage

    1. $f.updateRule(field,{
    2. props:{
    3. disabled: true
    4. }
    5. })

Bulk update component rules

  • Parameter

    • {object} rules
    • {bool} cover The default is deep copy, which is directly overridden when equal to true
  • Usage

    1. $f.updateRules({
    2. field1:{
    3. props:{
    4. disabled: true
    5. }
    6. },
    7. field2:{
    8. props:{
    9. disabled: false
    10. }
    11. }
    12. })

Get the specified component generation rule

  • Parameter{string} [field|name]

  • Return value{object}

  • Usage

    1. const rule = $f.getRule(field)

Get generation rules for form components

  • Return value{object}

  • Usage

    1. const model = $f.model()

    Get the generation rules of the form component. The component definition field property can be obtained

Get custom component generation rules

  • Return value{object}

  • Usage

    1. const component = $f.component()

    Get custom component generation rules, component definition NAME property can get

Call the method that generates the component

  • Parameter

    • {string} field/name
    • {string} methodName Component method name
  • Return valueFunction

  • Usage

    1. const val = $f.method('input','focus')();

Manually trigger events for the component

  • Parameter

    • {string} field/name
    • {string} eventName Component method name
    • ... args Event parameter
  • Usage

    1. $f.trigger('input','on-change','new value');

Get the vm / dom element of the component

  • Parameter

    • {string} field/name
  • Return valueVue|Element

  • Usage

    1. $f.el(field);

Form operations

Form validation

  • Parameter{function} callback

  • Usage

    1. $f.validate((valid)=>{
    2. if(valid){
    3. //TODO success
    4. }else{
    5. //TODO fail
    6. }
    7. })

Validate specified field

  • Parameter

    • {string} field
    • {function} callback
  • Usage

    1. $f.validateField(field,(errMsg)=>{
    2. if(errMsg){
    3. //TODO success
    4. }else{
    5. //TODO fail
    6. }
    7. });

Insert component

  • Parameter

    • {object} rule
    • {stirng} [field|name]
    • {boolean} isChild Whether to add to the children of the [field|name] component
  • Usage

    1. $f.prepend({
    2. type:"input",
    3. title:"goods info",
    4. field:"goods_info",
    5. value:"",
    6. props: {
    7. "type": "text",
    8. },
    9. validate:[
    10. { required: true, trigger: 'blur' },
    11. ],
    12. }, 'goods-name', false);

    Insert the specified form element before the field of field. Do not passfield by default. If isChild istrue, it will be added to the child of field.

Append component

  • Parameter

    • {object} rule
    • {stirng} [field|name]
    • {bool} isChild Whether to add to the children of the [field|name] component
  • Usage

    1. $f.append({
    2. type:"input",
    3. title:"goods info",
    4. field:"goods_info",
    5. value:"",
    6. props: {
    7. "type": "text",
    8. },
    9. validate:[
    10. { required: true, trigger: 'blur' },
    11. ],
    12. }, 'goods-name', false);

    Insert the specified form element after the field of field. Do not passfield by default. If isChild istrue, it will be added to the child of field

Submit the form manually

  • Parameter

    • {function} onSubmit
    • {function} fail
  • Usage

    1. $f.submit((formData,api)=>{
    2. //success
    3. },(api)=>{
    4. //fail
    5. })

    Submit the form manually.If you pass the onSubmit parameter, the option.onSubmit will not be triggered.

Hide or show the specified component

  • Parameter

    • {bool} hidden
    • {string|array} [field|name]
  • Usage

    1. $f.hidden(true)
    1. $f.hidden(true,field)
    1. $f.hidden(true, [field1,field2,field3,name1,name2])

Get component display status

  • Parameter{string} [field|name]

  • Return value{bool}

  • Usage

    1. const hiddenStatus = $f.hiddenStatus();

Disable or unassign components

  • Parameter

    • {bool} disabled
    • {string|array} field
  • Usage

    1. $f.disabled(true)
    1. $f.disabled(true, field)
    1. $f.disabled(true, [field1,field2,field3])

Clear component verification information

  • Parameter{string|array} field

  • Usage

    1. $f.clearValidateState();
    1. $f.clearValidateState(field);
    1. $f.clearValidateState([field1,field2]);

Gets whether the value in the form has changed state

  • Return value{bool}

  • Usage

    1. const status = $f.changeStatus()

Clear whether the value of the form has changed

  • Usage

    1. $f.clearChangeStatus()

Modify the form submit button rule

  • Parameter{object} props

  • Usage

    1. $f.submitBtnProps({loading:true})
  • Quick operation:

    • $f.btn.loading(loading = true) Set the submit button to the loading state
    • $f.btn.disabled(disabled = true) Set submit button disabled
    • $f.btn.show(isShow = true) Set the submit button display status

Modify the form reset button rule

  • Parameter{object} props

  • Usage

    1. $f.resetBtnProps({disabled:true})
  • Quick operation:

    • $f.resetBtn.loading(loading = true) Set the reset button to the loading state
    • $f.resetBtn.disabled(disabled = true) Set reset button disabled
    • $f.resetBtn.show(isShow = true) Set the reset button display status

Close the popup of the frame component

  • Parameter{string} [field|name]

  • Usage

    1. $f.closeModal(field)

Update global configuration

  • Parameter{object} options

  • Usage

    1. $f.updateOptions({
    2. onSubmit:(formData)=>{
    3. //submit Form
    4. }
    5. })

Modify form submission callback

  • Parameter{Function} [onSubmit]

  • Usage

    1. $f.onSubmit((formData)=>{
    2. //submit Form
    3. })

Control the overall display status of the form

  • Parameter{bool} isShow

  • Usage

    1. $f.hideForm(true)

Convert generation rules to json

  • Return value{string}

  • Usage

    1. const json = $f.toJson();

Manually re-render the specified component

  • Parameter{string} [field/name]

  • Usage

    1. $f.sync(field)

Reload form

  • Parameter{Array} [rules]

  • Usage

    1. $f.reload(newRule)

    Reload the form generator according to the new generation rules. If you do not pass in rules, the form generator will be reloaded according to the current rules.

Refresh form

  • Parameter{bool} [clear]

  • Usage

    1. $f.refresh(true)

    Re-render the form, clearing all components’ caches when clear is true

Reset form

  • Usage

    1. $f.resetFields()

Destroy form

  • Usage

    1. $f.destroy()

Listening to form events

  • Parameter

    • {string} emitName Generate rule emit event name
    • {Function} callback Callback method
  • Usage

    1. /*
    2. rule:{
    3. field:'goods-name'
    4. //...
    5. emit:['on-change']
    6. }
    7. */
    8. $f.on('goods-name-on-change',() => {
    9. //TODO
    10. });

Listen for form events, only fired once

  • Parameter

    • {string} emitName Generate rule emit event name
    • {Function} callback Callback method
  • Usage

    1. /*
    2. rule:{
    3. field:'goods-name'
    4. //...
    5. emit:['on-change']
    6. }
    7. */
    8. $f.once('goods-name-on-change',() => {
    9. //TODO
    10. });

    Listen for a custom event, but only fire once, remove the listener after the first trigger

Remove form event listener

  • Parameter

    • {string | Array} emitName Generate rule emit event name
    • {Function} [callback] Callback method
  • Usage

    Remove custom event listeners.

    -If no parameters are provided, remove all event listeners;

    -If only events are provided, remove all listeners for the event;

    -If both an event and a callback are provided, only the listener for this callback is removed.

    1. $f.off('goods-name-on-change');
    2. // $f.off('goods-name-on-change', fn);

$f.set

  • Parameter

    • {object} node
    • {string} key
    • {any} value
  • Usage

    1. $f.set(field.rule.col,'span',12)

    You can try this method if the page is not updated after modifying the rules of the component, the method is the same as Vue.$Set