Skip to content

Commit 8f2f44f

Browse files
committed
Merge pull request #100 from javigomez/experimentalChosen
[add] select Option in Chosen by Id Using Js
2 parents 61d7564 + d90e007 commit 8f2f44f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/JoomlaBrowser.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function selectOptionInChosen($label, $option)
429429
}
430430

431431
/**
432-
* Selects an option in a Chosen Selector based on its label
432+
* Selects an option in a Chosen Selector based on its id
433433
*
434434
* @param string $selectId The id of the <select> element
435435
* @param string $option The text in the <option> to be selected in the chosen selector
@@ -447,6 +447,27 @@ public function selectOptionInChosenById($selectId, $option)
447447
$I->wait(1); // Gives time to chosen to close
448448
}
449449

450+
/**
451+
* Selects an option in a Chosen Selector based on its id
452+
*
453+
* @param string $selectId The id of the <select> element
454+
* @param string $option The text in the <option> to be selected in the chosen selector
455+
*
456+
* @return void
457+
*/
458+
public function selectOptionInChosenByIdUsingJs($selectId, $option)
459+
{
460+
$I = $this;
461+
462+
$option = trim($option);
463+
$I->executeJS("jQuery('#$selectId option').filter(function(){ return this.text.trim() === \"$option\" }).prop('selected', true);");
464+
$I->executeJS("jQuery('#$selectId').trigger('liszt:updated').trigger('chosen:updated');");
465+
$I->executeJS("jQuery('#$selectId').trigger('change');");
466+
467+
// give time to Chosen to update
468+
$I->wait(1);
469+
}
470+
450471
/**
451472
* Selects one or more options in a Chosen Multiple Select based on its label
452473
*
@@ -831,16 +852,16 @@ public function setFilter($label, $value)
831852
"select tag" => "filter_tag",
832853
"select max levels" => "filter_level"
833854
);
855+
834856
$I = $this;
835857
$I->click(['xpath' => "//button[@data-original-title='Filter the list items.']"]);
836858
$I->debug('I try to select the filters');
859+
837860
foreach($filters as $fieldName => $id)
838861
{
839862
if($fieldName == $label)
840863
{
841-
$I->waitForElement(['xpath' => "//div[@id='" . $id . "_chzn']/a"], 10);
842-
$I->click(['xpath' => "//div[@id='" . $id . "_chzn']/a"]);
843-
$I->click(['xpath' => "//div[@id='" . $id . "_chzn']//ul[@class='chzn-results']/li[contains(.,'" . $value . "')]"]);
864+
$I->selectOptionInChosenByIdUsingJs($id, $value);
844865
}
845866
}
846867
$I->debug('Applied filters');

0 commit comments

Comments
 (0)