Last problem.
Scenario
- When building the rows in an editableList - each row has 1 dropdown and 3 typedInput widgets.
- At runtime, when the dropdown is changed, the typed widgets need to be shown/hidden accordingly
- This means I need to be able to address the actual typedInput to call show/hide functions.
The problem
It seems the invocation of typedInput doesnt return a reference to the newly created typedInput, nor do custom classes get applied - making it somewhat difficult to show/hide the typedInput
the question(s)
- Is it possible at invocation to specify a class (or ID) (for later access to the typedInput via a selector)
or
- Is there a function or call to the widget available to retrieve the associated typedInput?
Additional info & stuff I've tried...
After instantiating a typedWidget I try to show()
/ hide()
it but it doesnt work as the instance/object returned from the invocation of the typedWidget is the original <input>
.
The only workaround I have found is clunky (below is a handful of things I have tried and finally the workaround on the last line) ...
var payloadField = $('<input/>',{class:"node-input-payload",type:"text",style:"margin-left:7px; width:calc(23% - 16px);", placeholder: 'payload', value:option.payload || ""}).appendTo(div);
// $("node-input-payload") refers to the original payloadField input
var payloadTypedInput = payloadField.typedInput({default:'str',types:['flow', 'global', 'str', 'num', 'bool', 'json', 'bin', 'date', 'env']});
// payloadTypedInput === payloadField - meaning I dont have a ref to the typedInput
// PROOF: payloadTypedInput.is(payloadField) returns true :(
// So the next line actually adds the custom accessor class to the input not the widget.
payloadTypedInput.addClass("a-class-name-i-can-use-later-for-accessing-this-widget")
// payloadField.typedInput().option is null
// payloadField.typedInput("option","class", "my-class") doesnt work
// payloadField.typedInput( "option", "classes", "my-class" ) doesnt work
// payloadField.typedInput( "option", "css", "my-class" ) doesnt work
//Finally, the workaround - access the sibling div
var actualTypedInput = payloadField.find("+ div.red-ui-typedInput-container")
actualTypedInput.addClass("a-class-name-i-can-use-later-for-accessing-this-widget")
I have noted in the JQuery widget factory documentation, you should be able to add classes at widget creation time so I tried...
var payloadTypedInput = payloadField.typedInput({
classes: { "red-ui-typedInput-container":"node-input-payload-typed-input" },
default:'str',types:['flow', 'global', 'str', 'num', 'bool', 'json', 'bin', 'date', 'env']
});
... but that doesnt work (or likely, I'm doing it wrong).
I'm likely missing something simple here - anyone know how to handle this scenario better than retrieving the widget via a sibling selector?