0

This is my html :

 <select class="form-control input-sm" name="FloorId" data-bind="
                   options: $root.floors(),
                   optionsText: 'floorNumber',
                   optionsValue: 'id',                         
                   value :  floorId" required>
  </select>

   <button type="submit">save</button>

floorId is an observable variable. When the user changes the option floorId also is being updated. But i want this to heppen only then when the user clicks to the save button.

ucnobi ucnobi
  • 255
  • 1
  • 5
  • 16

1 Answers1

2

It sounds like you need to change your model a bit. The value binding is used to make sure your model reflects and is aware of the currently selected value in the UI.

You should introduce a new observable in your model that holds the "saved" value, that you can set from your existing currently selected value observable when the button is clicked. Doing otherwise is going to start fighting against knockout and the way it is designed to work.

James Thorpe
  • 31,411
  • 5
  • 72
  • 93