Vue select tag on change not firing when selecting the same option - vue.js

I have a select tag that should trigger function when an option is selected.
<select id="selector" class="form-control" #change="executeAction" v-model="selectedAction">
<option value="" selected disabled>Select action</option>
<option value="view">View Details</option>
<option value="edit">Edit</option>
<option value="delete">Delete</option>
</select>
methods: {
executeAction() {
console.log('action is se', this.selectedAction);
},
}
Now, what I expected was:
When selecting the same option for the second time (For example: View Details), it should log the selected option.
What I got:
It's not firing at all, I need to select other option so that I can reselect the View Details again.
What I tried:
Using watch, and the result was the same.
Using #input instead of #change, still result was same.
Usin v-on: instead of #, still no luck.
Is this a bug? or wrong implementation?
Anyways, would be great to have an answer to this.

Related

Set the value for <select> without using 'v-model'

I would like to have something like the following Vue template, but it does not work with the property selectedVal. What is the correct property name?
<select :selectedVal="myList" multiple>
<option value="abc">ABC</option>
</select>
For <input> the prop to bind is value, but for <select> it does not seem to be documented anywhere. I am looking for the name of the correct prop to bind.
I answered because it's difficult to quote code snippet in a comment.
I think you asked this question after looking into the document here, which showed an elegant way to define selected items.
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
Actually, I doubt if there's a v-bind prop performs like this because value is an attribute of input and option, but selected is not an attribute of select but an attribute of option and I can't find any alternatives in select.
Also, after browsing the source code of Vue.js, I didn't see vue did much for binding an attribute (code here and here) rather than pushing values of v-bind into the element's attrs list.
export function addAttr (el: ASTElement, name: string, value: string) {
(el.attrs || (el.attrs = [])).push({ name, value })
}
On the other hand, select seems to be an special case in v-model (see code here).
So, I provided the solution in the comment by binding selected to option instead of select.

Selenium webdriver select option

I'm trying to select an option from a select drop-down using Selenium/java/MS Edge driver, but I'm finding I can't select the option even though I can see I have located it.
My code so far;
final static String URL = "http://usedcars.bmw.co.uk";
final static String edgeDriverBinary = "MicrosoftWebDriver.exe";
System.setProperty("webdriver.edge.driver", edgeDriverBinary);
WebDriver driver = new EdgeDriver();
driver.get(URL);
// Click the field to activate the drop down
By byQsRangeBtn = By.xpath("//div[#id='quick-search']/form/fieldset[#class='form']/div/div[#class='js-ctm-dropdownlist']/div[#class='js-ctm-display']/span");
WebElement qsRangeElement = driver.findElement(byQsRangeBtn);
qsRangeElement.click();
Sending this click does activate the drop-down and I can see it expands
Select qsRange = new Select(driver.findElement(By.id("qsRange")));
log("OPTIONS: " + qsRange.getOptions());
In the above I can dump .getOptions() and I see all the data from the select options.
When I call this I just get an exception with no stack trace or useful logging information. I've tried .selectByIndex() and .selectByVisibleText() with the same result - an exception and no information.
qsRange.selectByValue("3648835");
The part of the page is below. The id="qsRange" is set as not visible in the page (grey'd out in firebug). class="js-ctm-display" is the only div that is visible.
If I manually click the drop down to display it's values then <div class="js-ctm-dropdownlist"> becomes <div class="js-ctm-dropdownlist js-open">, but firebug still sees the select as not displayed.
<form class="quicksearch mp-search-count" method="post" action="/search-cars.aspx">
<fieldset class="form">
<div class="search-control series js-ctm js-ctm-mode-full" data-theme-type="dropdownlist">
<div class="js-ctm-dropdownlist">
<select id="qsRange" class="mp-control-data" name="Range">
<option value="-1">Series</option>
<option value="890">1 Series</option>
<option value="3648873">2 Series</option>
<option value="66">3 Series</option>
<option value="3648835">4 Series</option>
<option value="67">5 Series</option>
<option value="68">6 Series</option>
<option value="69">7 Series</option>
<option value="3648830">X</option>
<option value="3648831">Z</option>
<option value="3648832">M</option>
<option value="3648938">PHEV</option>
<option value="3648833">Hybrid</option>
<option value="3648834">BMW i</option>
<option value="3648879">Alpina</option>
</select>
<div class="js-ctm-display">
<span>Series</span>
<span class="js-ctm-ico"></span>
</div>
If I manually select a value from the drop-down then I see class="js-ctm-display" becomes as below and the page then makes an ajax call to obtain values for subsequent drop-downs.
<div class="js-ctm-display">
<span>4 Series</span>
<span class="js-ctm-ico"></span>
</div>
Because I can tell that the page is making multiple ajax calls as I move through the options I believe I need to simulate user interaction (clicks) rather than being able to just set values. However my attempts at clicking on an option in the list aren't working out at all.
I've also attempted to get a WebElement for one of the option values with the intention of sending it a click, but that throws an exception saying the WebElement is expected to be a Select rather than an Option.
Does anyone have a view on how to approach this kind of page? I'm rather new to Selenium so expect my approach isn't the best.

PrestaShop: Get value of select menu

Is there any possible way to get a selected value in Prestashop without javascript? I tryed with Tools::getValue() but it doesn't work...
<select name="selectPosition" id="selectPosition">
<option value="0">---</option>
<option value="1">'.$this->l('Left').'</option>
<option value="2">'.$this->l('Right').'</option>
</select>
Best regards,
George!
Tools::getValue checks is value is in POST or in GET, just pass the value you want to check ad param
if (Tools::getValue('selectPosition') {
//make something
}

How to select a combobox in geb with groovy

This is what I have currently with Geb. I want to be able to retrieve and set the value of a combobox (or drop down) in a page. I'm not quite sure how to do it, and the Book of Geb does not seem to cover this. This is the HTML element that I'm trying to work with.
<select style="height: 22px; width: 370px;" id="ddlContactTypes" name="ddlContactTypes">
<option value="-1">--Please Select--</option>
<option value="18">Customer Hauler</option>
<option value="19">Customer General</option>
<option value="20">Rolloff</option>
<option value="21">Supplier</option>
<option value="22">Leads</option>
<option value="23">Competition</option>
<option value="24">Employees</option>
<option value="25">Customer Car</option>
<option value="26">Secondary Metals Recycler</option>
<option value="27">Mills</option>
<option value="28">Brokerage Customers</option>
<option value="29">Type Jon</option>
</select>
This is what I've go so far. This currently will click the element, but I don't know how to actually select one. Any ideas?
static content = {
title {$("title")}
contactType { $("#ddlContactTypes") }
}
def addUser(){
contactType.click()
}
You can select an option by setting the value of the geb object :
contactType.value('20')
Above example will set the value to '20', making the list show 'Rolloff' as selected.
U can see this
HTML
Alt folk
Chiptunes
Electroclash
G-Funk
Hair metal
GOOVY
$("form").artist = "1" // first option selected by its value attribute
$("form").artist = 2 // second option selected by its value attribute
$("form").artist = "Ima Robot" // first option selected by its text
http://www.gebish.org/manual/0.9.2/navigator.html
Manual descibes it in section Setting Values

Using .change() to addClass with select list

I'm trying to make a hidden field show by adding a class when the "other" option is selected from a pull-down list. But I'm not quite sure the correct way to do it.
I have the input hidden and when option is chosen I want to add the class "view" which adds display block making the hidden field visible.
Here is a fiddle showing what I have so far, any help would be much appreciated: http://jsfiddle.net/maikunari/NX795/
$(document).ready(function(){
$("#select-box").change(function(){
if($(this).val() == "other"){
$("#text-field").show();
} else {
$("#text-field").hide();
}
});
});
<select id="select-box">
<option value="Email Newsletter">Email Newsletter</option>
<option value="Yellow Pages ">Yellow Pages </option>
<option id="other-select" value="other">Other</option>
</select>