Giter Site home page Giter Site logo

knockout-x-editable's Introduction

knockout-x-editable

knockout binding handler for x-editable - See http://vitalets.github.com/x-editable

##Simple Usage NOTE: set any editable defaults before calling ko.applyBindings

for a view model:

var viewModel = function(){
  var self = this;
  self.id = ko.observable();
  self.firstName = ko.observable();
  self.lastName = ko.observable();
  self.gender = ko.observable();
  
  self.genders = ko.observableArray();
}

and binding:

<span data-bind="editable: firstName"></span>

will set editable options value (value of firstName) and name to firstName. Your observable is updated to the new value in the save event (you can also pass your own save event that gets called after).

##Advanced You can pass through any editable options with:

<span data-bind="editable: firstName, editableOptions: {name: 'first', pk: id, url: '/save'}"></span>

Note the pk can be an observable since x-editable just calls it as a function. The option editableOptions.visible can be passed an observable, this sets the x-editable toggle to 'manual', then uses the observable to fire the 'show' method

###select, checklist and typeahead options For select and checklist, you can pass options just as you would to knockout:

<span data-bind="editable: gender, editableOptions: {pk: id, options: genders, optionsText: 'text', optionsValue: 'id'}"></span>

For select only, you can also pass in the valueUpdate option (see http://knockoutjs.com/documentation/value-binding.html):

<span data-bind="editable: comment, editableOptions: { /* ... */, valueUpdate: 'keyup'}"></span>

optionsCaption is used to set editable.prepend

###knockout.validation If you are using knockout.validation, I have wired up a call to the observable's isValid for editable.validate. To work, this has to push the new value into the observable, then validate, then revert back. If you have subscribed to changes, you will see them. Not the best choice, but works.

knockout-x-editable's People

Contributors

brianchance avatar mteper avatar

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.