Search code examples
knockout.jscustom-componentoracle-jet

How do I implement textInput binding with OJET input text v5.2.0?


Knockout's textInput binding used to work with Oracle JET v3.2.0 ojInputText tag.

<input id="text-input" 
     type="text"
     data-bind="ojComponent: {component: 'ojInputText', 
                              textInput: value}"/>

But now that every single component of Oracle JET v5.2.0 is a custom HTML component, textInput doesn't work anymore. I've tried these methods:

<oj-input-text id="text-input" textInput="{{value}}"></oj-input-text>
<oj-input-text id="text-input" data-bind="textInput: value"></oj-input-text>

Is there a way to make textInput work with oj-input-text?

I've checked the documentation as well, but nothing is mentioned.


Solution

  • As confirmed by @Srishti, I can't use textInput with Oracle JET. So I created a Knockout Binding Handler to imitate the behaviour, which I believe others would find useful too:

    <oj-input-text data-bind="textInputOJET: value"></oj-input-text>
    

    JS:

    ko.bindingHandlers.textInputOJET = {
        init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
            $(element).focus(function(){
                $($(this).find('input')[0]).keyup(function(event){
                    valueAccessor()(event.currentTarget.value);
                });
            });
        },
        update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {}
    }
    
    self.value = ko.observable();
    self.value.subscribe(function(newValue){
        console.log(newValue);
    });