DoneJS StealJS jQuery++ FuncUnit DocumentJS
3.14.1
5.0.0 4.3.0 2.3.35
  • About
  • Guides
  • API Docs
  • Community
  • Contributing
  • Bitovi
    • Bitovi.com
    • Blog
    • Design
    • Development
    • Training
    • Open Source
    • About
    • Contact Us
  • About
  • Guides
  • API Docs
    • Observables
      • can-compute
      • can-define
      • can-define/list/list
      • can-define/map/map
      • can-define-stream
      • can-define-stream-kefir
      • can-event
      • can-event/async/async
      • can-event/batch/batch
      • can-event/lifecycle/lifecycle
      • can-kefir
      • can-list
      • can-map
      • can-map-backup
      • can-map-define
      • can-observation
      • can-observe
      • can-simple-map
      • can-simple-observable
      • can-stream
      • can-stream-kefir
    • Data Modeling
      • can-connect
      • can-connect-cloneable
      • can-connect-feathers
      • can-connect-ndjson
      • can-connect-signalr
      • can-fixture
      • can-fixture-socket
      • can-ndjson-stream
      • can-set
    • Views
      • can-component
      • can-ejs
      • can-element
      • can-react-component
      • can-stache
      • can-stache/helpers/route
      • can-stache-bindings
      • can-stache-converters
        • Examples
          • input[type=checkbox]
          • input[type=radio]
          • select
          • select[multiple]
        • Converters
          • boolean-to-inList
          • either-or
          • equal
          • index-to-selected
          • not
          • selected-to-index
          • string-to-any
      • can-view-autorender
      • can-view-callbacks
      • can-view-href
      • can-view-import
      • can-view-live
      • can-view-model
      • can-view-nodelist
      • can-view-parser
      • can-view-scope
      • can-view-target
      • react-view-model
      • react-view-model/component
      • steal-stache
    • Routing
      • can-deparam
      • can-param
      • can-route
      • can-route-pushstate
    • JS Utilities
      • can-assign
      • can-define-lazy-value
      • can-globals
      • can-key-tree
      • can-make-map
      • can-parse-uri
      • can-string
      • can-string-to-any
      • can-util
      • can-zone
      • can-zone-storage
    • DOM Utilities
      • can-ajax
      • can-attribute-encoder
      • can-control
      • can-dom-events
      • can-event-dom-enter
      • can-event-dom-radiochange
      • can-jquery
    • Data Validation
      • can-define-validate-validatejs
      • can-validate
      • can-validate-interface
      • can-validate-legacy
      • can-validate-validatejs
    • Typed Data
      • can-cid
      • can-construct
      • can-construct-super
      • can-namespace
      • can-reflect
      • can-reflect-promise
      • can-types
    • Polyfills
      • can-symbol
      • can-vdom
    • Core
    • Infrastructure
      • can-global
      • can-test-helpers
    • Ecosystem
    • Legacy
  • Community
  • Contributing
  • GitHub
  • Twitter
  • Chat
  • Forum
  • News
Bitovi

can-stache-converters

  • npm package badge
  • Star
  • Edit on GitHub

Provides a set of converters useful for two-way binding with form elements such as <input> and <select>.

Use

The can-stache-converters plugin provides a set of useful converters useful for binding to form elements.

Add a binding with a converter to an input or select element and the element's value will be cross-bound to an observable value specified by the binding attribute's value.

Depending on the element and the element's type, different behaviors to properly synchronize view model data and element attributes.

input type=text

value:bind="key" cross-binds the input's string text value with the observable value.

The value of the observable is changed after the input's change event, which is after blur.

input type=checkbox

checked:bind="key" cross-binds the checked property to a true or false value.

checked:bind="boolean-to-inList(~key, list)" cross-binds the checked property to key being added to / removed from list. The tilde (~) is important here because the compute it sets up acts as a channel between the element's property and the scope's property.

checked:bind="either-or(~key, checkedval, uncheckedval)" cross-binds the checked property to key, but uses the checkedval value to represent checked, and the uncheckedval value to represent unchecked.

input type='radio'

checked:bind="key" cross-binds the checked property to key being true or false.

checked:bind="equal(~key, value)" cross-binds the checked property to key having a value equal to value. This is useful for radio groups representing options for a single data property.

select

value:bind="key" cross-binds the selected option value with an observable value.

For multiple-selection lists, values:bind="key" cross-binds selected options with membership in key, with the requirement that key on the scope is an array-like or a string. If key is a string, it is treated as a comma-separated list of values.

textarea

value:bind="key" cross-binds the textarea's string text value with the observable value.

The value of the observable is changed after the textarea's change event, which is after blur.

There is a way of making changes respond to key events as well: on:keyup="scope.set('key', scope.element.value). However, this sets the value of key at the current scope level. If key was set at a higher level of the scope, the cross binding of value:bind will not point to the same item as the keyup target.

CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.14.1.

On this page

Get help

  • Chat with us
  • File an issue
  • Ask questions
  • Read latest news