Skip to content Skip to sidebar Skip to footer

Show/hide Based On Dropdown Selection In Knockoutjs With Model Inside Another Model

I am working on 'Rules' for form builder. I want to show/hide text box based on the dropdown selected. For example, let us assume we have a following 'Rules' for a 'TextField' cont

Solution 1:

The problems in your code:

  • The visible binding: selectedValue is a property in TextBoxViewModel, not in RuleConditionViewModel. Therefore, visible: ruleConditions().selectedValue() should only be visible: selectedValue
  • The optionsValue: 'Value' binding tells knockout to only store the Value property of a rule condition. I.e.: it stores the string isfilledout or contains. Remove it, and the whole object is stored.
  • Because the selectedItem was a string, the computed expression this.selectedItem() && this.selectedItem().isExpressionValueRequired was always false: the string prototype does not have a property named isExpressionValueRequired.

https://jsfiddle.net/hxchstp9/

Post a Comment for "Show/hide Based On Dropdown Selection In Knockoutjs With Model Inside Another Model"