Created
July 2, 2013 09:36
-
-
Save antony/5907972 to your computer and use it in GitHub Desktop.
Angular Select Box DSL Extension for retreiving Options.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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