Skip to content

Instantly share code, notes, and snippets.

@antony
Created July 2, 2013 09:36
Show Gist options
  • Save antony/5907972 to your computer and use it in GitHub Desktop.
Save antony/5907972 to your computer and use it in GitHub Desktop.
Angular Select Box DSL Extension for retreiving Options.
angular.scenario.dsl('selectBox', function() {
var chain = {};
chain.option = function(value) {
return this.addFutureAction("select '" + this.name + "' option '" + value + "'", function($window, $document, done) {
var select = $document.elements('select[name="$1"]', this.name);
var option = select.find('option[value="' + value + '"]');
if (option.length) {
select.val(value);
} else {
option = select.find('option:contains("' + value + '")');
if (option.length) {
select.val(option.val());
}
}
select.trigger('change');
done();
});
};
chain.options = function() {
return this.addFutureAction("select options'" + this.name, function($window, $document, done) {
var select = $document.elements('select[name="$1"]', this.name);
var option = select.find('option'), items = [];
for(var i = 0; i < option.length; i++) {
items.push(option[i].text);
}
done(null,items);
});
};
return function(name) {
this.name = name;
return chain;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment