-
-
Save fuel-lhartwell/cb0f3ec752d20af0e7d3 to your computer and use it in GitHub Desktop.
behat autoselect chosen.js
This file contains hidden or 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
| <?php | |
| use Behat\Mink\Exception\ElementNotFoundException; | |
| /** | |
| * @Given /^I select "([^"]*)" from "([^"]*)" chosen\.js autoselect box$/ | |
| */ | |
| public function iSelectFromChosenJAutoselectBox($option, $select) { | |
| $select = $this->fixStepArgument($select); | |
| $option = $this->fixStepArgument($option); | |
| $page = $this->getSession()->getPage(); | |
| $field = $page->findField($select, true); | |
| if (null === $field) { | |
| throw new ElementNotFoundException($this->getSession()->getDriver(), 'form field', 'id|name|label|value', $select); | |
| } | |
| $id = $field->getAttribute('id'); | |
| $javascript = "var select = jQuery('#$id > option:contains(\'$option\')').val(); | |
| jQuery('#$id').val(select).change().trigger('chosen:updated');"; | |
| $this->getSession()->executeScript($javascript); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment