Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Menu Option Not Disabling With Observable or Computed

ZacDJan 4 2018 — edited Jan 8 2018

Hello,

I'm doing my testing with JET 4.0 in Chrome and it seems that the 'disabled' attribute is not respecting changes in a Knockout observable or computed variable for oj-options in an oj-menu. Here's my first try using a pureComputed:

view.html

<oj-input-text value="{{inputValue}}"></oj-input-text>

<oj-menu-button>

Menu

\<oj-menu slot="menu" style="display:none">

    \<oj-option value="option1" disabled="\[\[optionDisabled\]\]">

        \<span data-bind="text: 'Option - ' + optionDisabled()">\</span>

    \</oj-option>

\</oj-menu>

</oj-menu-button>

viewModel.js

    self.inputValue = ko.observable('test');

    self.optionDisabled = ko.pureComputed(function() {

        var disabled = true;

        if(self.inputValue()){

            disabled = false;

        }

        return disabled;

    });

With that setup, I run the page and get this result:

pastedImage_2.png

Which is what I was expecting to start out. Now I remove the value from the input text and get this:

pastedImage_3.png

Note that the text on the menu option has changed to show the 'true' value, but the option is still enabled. Next, I changed the inputValue variable to default to empty and reran the page.

pastedImage_4.png

Option is disabled, which is exactly what I want. Now I enter a value into the input:

pastedImage_5.png

Again, the text on the menu option updated, but the option is still disabled.

Finally, I tried the same HTML code, but changed the JavaScript to use an observable and the observable.subscribe function to trigger the change.

viewModel.js

    self.inputValue = ko.observable('');

    self.optionDisabled = ko.observable(true);

    self.inputValue.subscribe(function(newValue) {

        if(newValue) {

            self.optionDisabled(false);

        } else {

            self.optionDisabled(true);

        }

    });

I am still getting the same result where the disabled state is not changing.

pastedImage_7.png

pastedImage_8.png

Both of the above mentioned methods are working fine for controlling the disabled state of normal buttons and other input text fields, just not the oj-menu oj-options.

This post has been answered by John JB Brock-Oracle on Jan 8 2018
Jump to Answer
Comments
Post Details
Added on Jan 4 2018
2 comments
444 views