Custom widget set read only based on dataview setting

1
I would like to have a function in a custom widget that will set an input box to read only based on the edit-ability setting of the surrounding dataview. I would like to have the input field in the widget to work in the same way that a standard input field would. The standard input fields will be set to read only if the dataview that surrounds the field is set to read only. Does anyone have a piece of sample code that would get me on the right track?
asked
1 answers
3

When the data view is read only or has no context it will put every widget in disabled state by setting the disabled property:

widget.set("disabled", true);

This will call the corresponding setter, which you will need to implement in your widget:

_setDisabledAttr: function(value) {
    if (value) {
        this.inputNode.setAttribute("disabled", "");
    } else {
        this.inputNode.removeAttribute("disabled");
    }

    this.inherited(arguments);
}

The getter will give you the current state:

this.get("disabled"); // returns whether this widget is disabled
answered