Skip to content
This repository has been archived by the owner on Jul 7, 2018. It is now read-only.

Latest commit

 

History

History
78 lines (61 loc) · 2.45 KB

README.md

File metadata and controls

78 lines (61 loc) · 2.45 KB

ampersand-select-view

A view module for intelligently rendering and validating selectbox input. Works well with ampersand-form-view.

Part of the Ampersand.js toolkit for building clientside applications.

install

npm install ampersand-select-view

example

var FormView = require('ampersand-form-view');
var SelectView = require('ampersand-select-view');


module.exports = FormView.extend({
    fields: function () {
        return [
            new SelectView({
                label: 'Pick a color!',
                // actual field name
                name: 'color',
                parent: this,
                // you can pass simple string options
                options: ['blue', 'orange', 'red'],
                // if included this will add option for an unselected state
                unselectedText: 'please choose one',
                // you can specify that they have to pick one
                required: true
            }),
            new SelectView({
                name: 'option',
                parent: this,
                // you can also pass pairs, first is the value, second is used for the label
                options: [ ['a', 'Option A'], ['b', 'Option B'], ['c', 'Option C'] ]
            }),
            new SelectView({
                name: 'model',
                parent: this,
                // you can pass in a collection here too
                options: collection,
                // and pick an item from the collection as the selected one
                value: collection1.at(2),
                // here you specify which attribute on the objects in the collection
                // to use for the value returned.
                idAttribute: 'id',
                // you can also specify which model attribute to use as the title
                textAttribute: 'title',
                // here you can specify if it should return the selected model from the
                // collection, or just the id attribute
                yieldModel: false
            })
        ];
    }
});

browser support

testling badge

credits

Written by @philip_roberts.

license

MIT