Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

AJAX data sources and multiple tokens#16

Open
andrewsnowden wants to merge 3 commits into
tactivos:masterfrom
andrewsnowden:ajax-values
Open

AJAX data sources and multiple tokens#16
andrewsnowden wants to merge 3 commits into
tactivos:masterfrom
andrewsnowden:ajax-values

Conversation

@andrewsnowden
Copy link
Copy Markdown

I've added some functionality that I needed, not sure if you'd like to pull these upstream.

You can fetch data remotely using an onFilterChanged callback and a setValues call. You can also specify a list of tokens to match (e.g. ["@", "#"]). I've added a demo for both of these functions in the demo.html

Added an onFilterChanged callback which is called whenever the filter
expression changes.
This can fetch data remotely and use the setValues to populate the
newly updated set of values.
An example of using this to show Github repositories is included in the
demo page.
Tokens can be passed in as an array.
The token that was matched is passed into the elementFactory as well as
the onFilterChanged callback
@chrisgraham
Copy link
Copy Markdown

Thanks for that, you saved me.

Note that this code is not compatible with IE8, without changes. The forEach needs changing to a regular for loop, and you need some polyfills..

if (!Array.prototype.filter) {
  Array.prototype.filter = function(
     a, // a function to test each value of the array against. Truthy values will be put into the new array and falsy values will be excluded from the new array
    b, // placeholder
    c, // placeholder 
    d, // placeholder
    e  // placeholder
  ) {
      c = this; // cache the array
      d = []; // array to hold the new values which match the expression
      for (e in c) // for each value in the array, 
        ~~e + '' == e && e >= 0 && // coerce the array position and if valid,
        a.call(b, c[e], +e, c) && // pass the current value into the expression and if truthy,
        d.push(c[e]); // add it to the new array

      return d // give back the new array
  };
}

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (searchElement , fromIndex) {
    var i,
        pivot = (fromIndex) ? fromIndex : 0,
        length;

    if (!this) {
      throw new TypeError();
    }

    length = this.length;

    if (length === 0 || pivot >= length) {
      return -1;
    }

    if (pivot < 0) {
      pivot = length - Math.abs(pivot);
    }

    for (i = pivot; i < length; i++) {
      if (this[i] === searchElement) {
        return i;
      }
    }
    return -1;
  };
}

Also note the code is not compatible with jfelsinger's second token delimiter regexp workaround in #6. That's fine though, that was kind of a hack. The first token delimiter workaround (removing \b) still works.

@andrewsnowden
Copy link
Copy Markdown
Author

Thanks, will try dig out a copy of IE8 and patch and test on that as soon as I get a chance

@chrisgraham
Copy link
Copy Markdown

Oh, actually I assumed that this was a problem in your code, and I just realised it wasn't - it's an original 'bug' (incompatibility, really) in sew. Sorry for pinning it on you ;).

@smilesrg
Copy link
Copy Markdown

Why don't you accept this PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants