Giter VIP home page Giter VIP logo

meteor-autoform-dropdown-select's Introduction

Dropdown-Select (for Autoform + Bootstrap 3)

A custom Dropdown-Select (with Method-based search) for Autoform.
The available options will be fetched by Methods! (So you don't need to handle Subscriptions - e.g. for huge data stacks...)

Install

meteor add andruschka:autoform-dropdown-select

(Of course you need Bootstrap and Autoform installed first!)

Usage

Just create 2 Methods for fetching the data. The first one is for getting the option Object for an already set value (for example if you are updating an exiting document). The second is for fetching search results as selectable options.

The option Object

Each option Object needs a value (this will get stored to the DB) and a label (this will be displayed).

= {value: "1003", label: "Betawerk"}

Initial Method

Gets (only) invoked by an "update" autoform-field (to get the label for the set value)

  • Passes param: the current value of the doc
  • Needs to return: an Object (containing a value and label)

Search Method

Gets invoked when the user types in the search field.

  • Passes Param: the current searchString
  • Needs to return: an Array with Objects (containing a value and label)

Example

Meteor.methods({
  "supplier_option_by_no": function(no) {
    // initial fetch
    let supplier =  Suppliers.findOne({no})
    // the first Method should return one! doc with label & value
    return {label: supplier.name, value: supplier.no}
  },
  "suppliers_options": function(searchString){
    // for searching
    var result = []
    if (searchString) {
      let rgx = new RegExp(`${searchString}.*`, 'i')
      result =  Suppliers.find({name: rgx}, {limit: 10}).fetch().map(sup => { 
        return {label: sup.name, value: sup.no}
      })
    }
    // the second Method should return the search results as array
    // a result also contains a label and a value
    return result
  }
})

Then just set "autoform.type" to 'dropdown-select' and pass the fetchMethods like this:

var Item = new SimpleSchema({
  name: {
    type: String,
    index: 1,
    label: "Item Name"
  },
  supplierNo: {
    type: String,
    label: "Supplier",
    autoform: {
      type: 'dropdown-select',
      placeholder: "Select Supplier", // placeholder for button ...
      inputPlaceholder: "Type something ...", // ... and for input
      fetchMethods: {
        initial: 'supplier_option_by_no',
        search: 'suppliers_options'
      }
    }
  }
})

Stylings

Example

{
  autoform: {
    type: 'dropdown-select',
    // ...
    fullWidth: true, // make it fullwidth | default: false
    className: "dropdown-dropup" // custom class name for the dropdown element | default: ""
  }
}

meteor-autoform-dropdown-select's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.