Home

fQuery alpha released

Nov 23, 2006

I've finished a first version of fQuery. In case you missed my earlier blog entry, here's the scoop:

fQuery is a selecting mechanism inspired by jQuery, which makes writing (amongst other things) Drupal form_alter hooks much easier. Specifically, it means you don't need to manually iterate over the entire $form tree just to find certain elements.

All you do is pass it a selector based on the familiar CSS syntax, and you get an array of matching elements back. There's plenty of voodoo magic under the hood, but the usage is ridiculously simple:

<?php
$query
= f("fieldset.collapsible", $form);
foreach (
$query as &$element) {
  ...
}
?>

fQuery supports a variety of selectors from CSS1, 2 and 3. Some selectors which were rather difficult to implement, or which were of little practical use, were not included.

Downloads and documentation are on the fQuery page.

Note that it is easy to extend fQuery to provide useful results for other Form API-like structures, e.g. the node view array. There's lots of potential here.

Check it out and post your comments!

Ridiculously Cool

Nov 23, 2006 Harry Slaughter

I know I'll be using this.

Thanks!

inc not ideal

Nov 23, 2006 Moshe Weitzman

the problem with a .inc file is that every module that wants to use this has to include it in own package. this will lead to function name conflict if two modules both want to use fquery. i think a module is better.

i will give it some testing and feedback.

Module

Nov 23, 2006 Steven

You're right. I converted it into a simple module that modules can depend on. It's now in Drupal.org Contrib and should appear on the project page soon.

independent of Drupal?

Nov 25, 2006 Fil

I'm sure I would use this lib if it were independent of Drupal. I don't use Drupal, but I love jQuery and would love to have the php equivalent.

From reading the code it seems that element_children() is the only function it needs from "elsewhere". And what is the $form prototype?

Form API

Nov 26, 2006 Steven

This code only works with Drupal Forms API arrays, which must have a specific structure.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <img> <em> <p> <br> <span> <div> <h2> <h3> <abbr> <small> <table> <tr> <td> <strong> <acronym> <th> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Recent comments

Images