HTML:
<select ng-model="productList.name" ng-options="productItem.uuid as productItem.name for productItem in product.items">
</select>
Render :
<option value="prod_1">Product 1</option>
<option value="prod_2">Product 2</option>
When we select any option in drop down list i need to show label value like Product 1 or Product 2.
So we make at ng-model for productList.label.
but we get "prod_1" or "prod_2"
Related
I have multiple select with the same name like this :
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
in php code i have :
$atest = $_POST['test'];
print_r($atest);
But, I got only data from not empty select, how to force $_POST to include all select disregarding it has value or not, so the array contains always 4 items.
thank you.
Multiple select you can use
<select name="test[]" size="7" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
After request you check $_POST['test'] is array that contains selected options
$test = $_POST['test'];
var_dump($test);
I have two dropdown menus in an Angular form. One is country and the other is country dialing code. When the user selects USA on the first dropdown, I want to update the second dropdown to default to +1 for the dialing code. Otherwise, the second dropdown should deafult to the placeholder "Select Country Code". I have successfully done this using javascript, but Angular still considers the form to be invalid when submitted. I've tried forcing the field to become valid in the javascript, but it doesn't seem to work. Is there a way to do this using javascript or an ng command in the HTML? I would like to keep the html formatted as is (i.e. with the select and options tags).
HTML:
<select required
class="form-control vertical-gap-5--bottom color-gray--warm-8"
id="country" name="country" type="text"
ng-model="contactSession.country">
<option data-countryCode="UG" value="256">Uganda</option>
<option data-countryCode="UA" value="380">Ukraine</option>
<option data-countryCode="AE" value="971">United Arab Emirates</option>
<option data-countryCode="GB" value="44">United Kingdom</option>
<option data-countryCode="US" value="1">United States</option>
<option data-countryCode="UY" value="598">Uruguay</option>
<option data-countryCode="UZ" value="998">Uzbekistan</option>
</select>
<select required
class="form-control vertical-gap-5--bottom color-gray--warm-8"
id="countryCode" name="countryCode" type="text"
ng-init="contactSession.countryCode = '1'"
ng-model="contactSession.countryCode">
<option value="" selected="selected">Select Country Code</option>
<option data-countryCode="UA" value="380">Ukraine (+380)</option>
<option data-countryCode="AE" value="971">United Arab Emirates(+971)</option>
<option data-countryCode="GB" value="44">United Kingdom (+44)</option>
<option data-countryCode="US" id="usaSelection" value="1">United States (+1)</option>
<option data-countryCode="UY" value="598">Uruguay (+598)</option>
</select>
JS:
$('select[name=country]').change(function () {
if ($(this).val() == '1') {
document.getElementById("countryCode").value = document.getElementById("usaSelection").value;
} else {
document.getElementById("countryCode").value = "";
}
});
I've made a fiddle, but I am not sure whether this is same as your intent or not.
Change select box
<select ng-options="country.code as country.nameAndCode for country in countries"
ng-model="selectedCountryAndCode"
ng-change="changeCountryAndCode();"
required>
<option value="">Select Country Code</option>
</select>
If you use 'ng-options', it'll make code more simple.
.
.
UPDATE
Here's updated fiddle.
A little modified following as I've understood.
.
.
.
Latest UPDATE
Here's another updated fiddle
Usually We do cascading Dropdown list with separate Select Box. Like below Image.
My requirement is quite different. I want to add only Single Select Box which will act as Cascading behaviour.
Simple Example process : (yourSelectBox - name of Select Box)
1) At First Instance It will show countries name in yourSelectBox
2) lets say , If you select/click India as Coutry,
3) now yourSelectBox should have States List like Maharashtra, Gujrat etc
4) If you select Maharashtra as your state,
5) how yourSelectBox should have City List.
6) finally you select your city.
Refer below image.
Can we flush values of yourSelectBox by keeping eye on event(using $watch on selected Value) ?
HTML
<select ng-mode="selcountry" ng-change="getStates();">
<option value="coutry.id" ng-repeat="coutry in countries"> {{coutry.name}}</option>
</select>
<select ng-mode="selstate" ng-change="getCities();">
<option value="state.id" ng-repeat="state in states"> {{state.name}}</option>
</select>
<select ng-mode="selcity" >
<option value="city.id" ng-repeat="city in cities"> {{city.name}}</option>
</select>
Controller :
$scope.getStates = function (){
//$scope.selcountry
//call get states where counties is $scope.selcountry
}
$scope.getStates = function (){
//$scope.selcountry
//call get states where counties is $scope.selcountry
$scope.states= result //set states to
}
$scope.getCities = function (){
//$scope.selstate
//call get states where counties is $scope.selstate
$scope.cities = result //set cities to
}
if you want the complete Login in Single Select Menu Then:
<select>
<optgroup label="India">
<optgroup label="Gujarat">
<option value="1">Gandhi Nagar</option>
<option value="2">Porubandar</option>
</optgroup>
<optgroup label="Delhi">
<option value="3">Delhi-6</option>
<option value="4">city</option>
</optgroup>
</optgroup>
</select>
Refer
In my requirement Initially it will show only search button not drop-down. Now, I need to show select list option directly when user click on search button instead of clicking on drop-down list. So I can get options when I click on search button and I can select any of them and once selected one option need to show another drop-down. Here is my code
<a><button>search</button></a>
<select><option value="">A</option><option value="">B</option>
<option value="">C</option>
<option value="">D</option>
</select>
here is fiddle http://jsfiddle.net/8bhvhq62/3/.
You could use ng-disabled directive here which would enable and disable the dropdown
Markup
<a><button ng-click="enabled=true">search</button></a>
<select ng-model="test" ng-disabled="!enabled">
<option value="">A</option>
<option value="">B</option>
<option value="">C</option>
<option value="">D</option>
</select>
<select ng-model="test1" ng-disabled="!enabled">
<option value="">1</option>
<option value="">2</option>
<option value="">3</option>
<option value="">4</option>
<option value="">5</option>
</select>
Fiddle Here
Simply trying to make a default selected value in Angular but thus far I am having no luck.
HTML Before Compile:
<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" ng-init="rule.MatchLogic = 0" ></select>
HTML In Browser Source:
<select ng-options="select.Value as select.Name for select in ruleSelect" ng-model="rule.MatchLogic" class="ng-pristine ng-valid">
<option value="?" selected="selected"></option>
<option value="0">All</option>
<option value="1">At Least</option>
<option value="2">At Most</option>
</select>
How do I make value=0 (All) the default selected value.
All you need to do is set your ng-model value rule.MatchLogic to equal the corresponding value in the options. The options you use are ruleSelect.
So for example, set rule.MatchLogic = ruleSelect[someSelector].Value; inside your controller.