In jQuery I would do:
var foo = jQuery("form");
foo.each(function(){
this.find(".required").each(function(){...})
})
This would find every required field in a form currently processed.
But as I have to use Dojo I'm kind of lost. In Dojo you need to use dojo.forEach()
var foo = dojo.query("form");
dojo.forEach(foo, function(self,i){
// And now I have no idea on what to use the forEach.
// The "self" parameter is the form node. So now I
// would need something like `self.forEach`
// But that obviously does not work
}
You just need to do another query again, like you did in the first level. The philosophy in Dojo is that things are usually less "magic" then they are in jQuery.
var forms = dojo.query("form"); //No second argument; Searches whole document
dojo.forEach(forms, function(form){
var requireds = dojo.query(".required", form);//Only search under
// the current form.
dojo.forEach(requireds, function(required){
/* do stuff*/
});
})
I also took the liberty to change the name of the self variable (since unlike jQuery, Dojo does not change the this
) and removed the optional i
parameter from the forEach.