Questions tagged [knockout-3.2]

Knockout.js is an open source JavaScript library for dynamic HTML UIs using the Model-View-View Model (MVVM) pattern. Version 3.2 adds "components" to bring a new and hugely more scalable way of structuring a large application.

Knockout.js is an implementation of the Model-View-View Model (MVVM) UI pattern. This tag is for questions specific to the 3.2 versions. Refer to the main tag for general information.

Version 3.2.0 brings (amongst others):

  • Components and Custom Elements;
  • ko.pureComputed observables;
  • A textInput binding to replace value bindings with valueUpdate options.
  • Several fixes and minor updates.
29 questions
3
votes
1 answer

Use required attribute in knockout.js

How can I conditionally set a required attribute in an input ? The required attribute has not value. Just by being present will be taken as required. So required="false" will make some scripts fail. I was not able to…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
3
votes
2 answers

knockout.js external templates without require.js

I'm wondering if there's another way of using templates in knockout.js without having to use require.js to load them dynamically. It adds around 20Kb after minification more to the site and it seems we are loading quite a big library to do something…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
2
votes
1 answer

Passing multiple viewmodels to a component - performance issues?

Using knockout.js components I'm wondering if performance get affected when passing multiple viewmodels to a component instead of just a single one. Having the following: function masterViewModel(){ this.demo = new demoViewModel().init(); …
Alvaro
  • 37,936
  • 23
  • 138
  • 304
2
votes
2 answers

Use a knockout component without the view model .JS file?

I'm trying to create a knockout component and load its template from a file like so: function ordersViewModel(){ //whatever } function equipmentViewModel(){ //whatever } ko.components.register('compact-view', { viewModel:…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
2
votes
2 answers

Dynamically load views / templates in knockout.js

I have a table and I want to show it in two different ways. Different number of columns and position of its content and cells. I would like to provide users with a way to change from one to another view by just clicking a button. I started doing it…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
2
votes
1 answer

Why does this observable become a computed / dependent when passed into component?

I have a simple model, and on there is an observable ("model.thing"). I then set an additional observable on this ("someProp") and pass it into the params of a component. model.thing = ko.observable({}); model.thing.someProp =…
4imble
  • 12,803
  • 14
  • 64
  • 119
1
vote
1 answer

Knockout.js binding in

I'm trying to add a binding in the element of the site and it doesn't seem to have any effect. Is there any restriction applying bindings in elements outside the body element?
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
2 answers

Passing the event object to knockout.js function

I'm using bind to call the function with parameters from my view: As per this answer I'm getting the event object by doing this: self.modifyByOne = function(type){ var span =…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
5 answers

preventDefault() `click` in Knockout.js 3

I have a data-bind="click: ..." event in Knockout.js and I'm trying to disable it whenever a disabled class is presence in the element. Two I'm trying this without…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
1 answer

Knockout js component using 'with' binding not behaving as expected

I have the following code from the JSFiddle I have setup: https://jsfiddle.net/ktce56hr/2/ var RootViewModel = function() { var self = this; this.rootText = ko.observable('default text'); this.rootFunc = function() { …
Alex Hope O'Connor
  • 8,758
  • 20
  • 65
  • 107
1
vote
2 answers

KnockoutJS checked binding with radio button

I have a list of objects that I loop through and create radio button for them, then I would like to store the object that is selected in an observable, but I cant figure out how to do this. This fiddle is example of something that im trying to do:…
Multi Load
  • 307
  • 1
  • 12
1
vote
1 answer

Mixing knockout code with jQuery in the same module?

I'm using a module pattern for my jQuery / javascript code and I'm using self executed functions for it as I'm doing for Knockout.js. (same as in the official knockout.js tutorials). This is probably a very subjective question to ask, but I would…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
1 answer

Structure knockout.js application in different files

I'm staring with Knockout.js and I didn't find much documentation about how to properly structure a knockout application. It is easy to follow the tutorial from the docs and its multiple examples in them or in other pages, but there's no much about…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
2 answers

Call function from outside master view model in knockout.js

I've seen similar topics about it, but none of them using exactly the same structure as me. I am using multiple view models and I deal with it by creating a MasterModel function which later on I pass as an argument to applyBindings. Basically…
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
vote
1 answer

Call function on input change with knockout.js (valueUpdate)

I'm trying to call a function when my input value gets updated. The function will validate the input value and set a flag to true or false which will be used in multiple elements in the DOM. I have been trying the proposed solution here:
Alvaro
  • 37,936
  • 23
  • 138
  • 304
1
2