Dojo disable all input fields in div container
dojo, input
Solution
Sure there is. Open up this form test page for example, launch FireBug and execute in the console:
var container = dojo.query('div')[13];
console.log(container);
dojo.query('input', container).forEach(
function(inputElem){
console.log(inputElem);
inputElem.disabled = 'disabled';
}
)
Notes:
- On that test page form elements are actually dijit form widgets, but in this sample I'm treating them as if they were normal input tags
- The second dojo.query selects all input elements within the `container` element. If the container had some unique id, you could simplify the sample by having only one dojo.query: `dojo.query('#containerId input').forEach( ...`
- forEach loops through all found input elements and applies the given function on them.
Update: There's also a shortcut for setting an attribute value using NodeList's `attr` function instead of `forEach`. attr takes first the attribute name and then the value or an object with name/value pairs:
var container = dojo.query('div')[13];
dojo.query('input', container).attr('disabled', 'disabled');
Problem
Is there any way to disable all input fields in an div container with dojo? Something like: ``` dijit.byId('main').disable -> Input ```