Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#7749 closed enhancement (duplicate)

In options, support functions wherever selectors can be used

Reported by: cowboy Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: 1.8.16
Keywords: Cc:
Blocked by: Blocking:


It would be great if Widget had a helper function like this (but better named):

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? : $(arg);

This function, when used to process an option, would allow a user to pass in a value that's a:

  • CSS selector string
  • DOM element
  • Array of DOM elements
  • jQuery object
  • Function that returns a jQuery object.

I used this code in a recent project, and it really helped. I'd even go so far as to say that anywhere a selector string (or any of the other preceding bullet point items) can currently be used, this processing could automatically be applied.

Of course, if a selector string is used, it doesn't do a relative find by default, but the tradeoff is that it offers a lot more flexibility. If that were a problem:

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? : this.element.find(arg);

Maybe this would be the most consistent / backwards compatible with jQuery UI:

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? : this.element.find(arg);

Either way, those are my 2¢. Thanks.

Change History (3)

comment:1 Changed 11 years ago by Corey Frang

im in support of something like this - maybe even _find for a name if it echoes .element.find()

comment:2 Changed 11 years ago by Scott González

Resolution: duplicate
Status: newclosed

comment:3 Changed 11 years ago by Scott González

Duplicate of #4957.

Note: See TracTickets for help on using tickets.