Ionic select is not changing to the correct values on change - ionic-framework

I have an ion-select where on change, I need to update values in other ion-select that is related.
The first ion-select is for selecting countries, then according to the specified one, the second ion-select will display the related major cities.
The problem that is cities displayed are always the one of the following array: kuwait_ar except of the country of Kuwait , where the cities are the correct ones kuwait_en.
Here is a stackblitz.
Here is the code for (ionChange):
displayCities()
{
let country = this.formGroup.controls.country.value;
this.cityArray = [];
//console.log(country)
this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
//console.log(this.cityArray)
}

Your problem is happening because you are assigning this.cityArray multiple times. The reason "Kuwait" works correctly, is because it is the last one in the list.
Consider when you select "Bahrain":
#1 this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
#2 this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
#3 this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
#4 this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
#5 this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
#6 this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
Line #1 correctly sets this.cityArray = this.bahrain_cities_er because your condition (country == "Bahrain" evaluates to true AND this.lang is set to "en"... GOOD
But... Line #2, (country == "Oman" || country == "عمان") evaluates to false, so your are reassigning the value of this.cityArray = this.oman_cities_ar
The same goes for Line #3-#6, thus the last line assigns it to this.kuwait_cities_ar as you have experienced.
Perhaps a switch statement would work better when only once case gets executed.
However, your approach is very complicated. You could structure your definitions of country/city names in a nested array or map, so you can simply "look up" the correct list, rather than "figure it out" based on a selected value. You could also two separate lists, one for each language, then simply swap them out based on the current language.

Related

pass decimal column value to populate results from a table using linq query

I have a product table with 20 column. There is a column 'Width' which is decimal data type. I have been calling particular width value in web api controller to populate results. As an example,width values are like below:
Width values
1 0.0015
2 1.0000
3 0.0063
4 1.0100
5 2.0000
6 2.0630
public HttpResponseMessage GetclassByWidthList(Decimal cWidth)
{
using (CrossReferenceTool1Entities cls1 = new CrossReferenceTool1Entities())
{
**var query = (from u in cls1.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && **u.Width == cWidth**) select u.Class).Distinct().ToList()**;
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
method is working fine. results are reflected if width value is "1.0000" OR "2.0000" but for other values of width it is not populating any result.
Please help me on above query where other decimal values with precision will populate result.
i have tried in browser to populate result:
1.
http://localhost:55481/api/KendoCascading/GetclassByWidthList/1 - result is poupulating
`http://localhost:55481/api/KendoCascading/GetclassByWidthList/1.01 - http-404 error showing
For debugging, your decimal data of Cwidth is being truncated, Please check
As per Ehasanul's suggestion i Just modified my method with putting extra "/" last of that route path
[Route("**api/KendoCascading/GetclassByWidthList/{cWidth:decimal}/**")]
public HttpResponseMessage GetclassByWidthList(decimal cWidth)
{
using (CrossReferenceTool1Entities cls1 = new CrossReferenceTool1Entities())
{
var query = (from u in cls1.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && u.Width == cWidth) select u.Class).Distinct().ToList();
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
call that url in my angular service http.get method with adding extra "/" in last.
this.getclsWidthList3 = function (cWidth) {
var res;
if (cWidth !== 0.0000) {
res = $http.get("/api/KendoCascading/GetclassByWidthList"+ "/"+ cWidth+"/");
return res;
}
};
and its working great.

Creating rules having complex conditions using multiple data objects

Assume that I have two data objects Person and Address. Person object has the fields name and gender and Address object has the fields city and state. Now I want to take some action based on this condition :
when
(person.name == 'jayram' && address.city == 'barhiya') ||
(person.gender == 'M' && address.state == 'bihar')
then
do something
How to accomplish this in drools rule file?
Maybe this should be the solution:
package com.sample
dialect "mvel"
import com.sample.Person;
import com.sample.Address;
rule "Hello World"
when
person : Person( status == Message.HELLO)
Address((person.name == 'jayram' && city == 'barhiya') ||
(person.gender == 'M' && state == 'bihar'))
then
// Do something
end

Why doesn't this form code work? It seems logical

I'm trying to program a simple form that asks for the following inputs:
mood, age, and gender
It does not matter what I put in the mood prompt. It always comes out positive. For the age, I would like the tab to close if they are under 18 years old. For gender, it goes the same with the mood prompt. Any help would be appreciated.
var userMood = prompt("Hey! How's it going?");
if (userMood = "good" || "Good") {
alert("Awesome! We just need you to fill out a form for security reasons.");
} else if (userMood != "good" || "Good") {
alert("Oh, I'm sorry to hear that... We just need you to fill out a form for security reasons.");
}
var userAge = prompt("What is your current age?");
if (userAge >= "18" ) {
alert("Great! You are the sufficient age to enter this webpage!");
userAge = true;
} else if ( userAge <= "17"){
alert("Sorry, you are too young to view this content...");
window.close();
}
var userGender = prompt ("What is your gender?");
if (userGender = "male" || "Male" || "female" || "Female"){
alert("Great! You're human!");
userGender = true;
} else {
alert("The webpage has perdicted non-human cyber activity, you can no longer continue.");
window.close();
}
i'm going to make my answer verbose to help you learn. for starters, you are using = when you mean to use == or even ===. this is why the mood is always registering as good, because userMood = "good" sets userMood to 'good' and so the expression evaluates to "good", which validates the if statement because FALSE for strings is "" and true is every other string. also userMood = "good" || "Good" doesn't do what you think it does. you need to check both strings like so (userMood === "good" || userMood === "Good").
I tried varying some lines in your code into something below.
var userMood = prompt("Hey! How's it going?");
if (userMood == "good" || userMood == "Good")
alert("Awesome! We just need you to fill out a form for security reasons.");
else
alert("Oh, I'm sorry to hear that... We just need you to fill out a form for security reasons.");
var userAge = prompt("What is your current age?");
if (userAge >= 18 )
{
alert("Great! You are the sufficient age to enter this webpage!");
userAge = true;
}
else if ( userAge < 18 && userAge > 0)
{
alert("Sorry, you are too young to view this content...");
window.close();
}
else if ( userAge < 0 )
{
alert(" ***** prompt message for inputting negative number ****");
window.close();
}
var userGender = prompt ("What is your gender?");
if (userGender == "male" || userGender == "Male" || userGender == "female" || userGender == "Female")
{
alert("Great! You're human!");
userGender = true;
}
else
{
alert("The webpage has perdicted non-human cyber activity, you can no longer continue.");
window.close();
}

Linq to Entities: multiple criteria query for one table

using (WinFileContextContainer c = new WinFileContextContainer())
{
IQueryable<File> dbfiles = (from f in c.File
where //(f.Category.Any((category => category.name == categoryname)) &&
f.alive //&&
//f.description == "" &&
//f.Category.Count == 1)
select f);
// the rest....
}
The query works only as it is now - I left just one criteria (the rest is in comment sections). But I want the other criteria to be taken into account too. I tried with multiple "where"s :D or all the criteria in brackets with one "where", but still no success. I'm kinda new to LINQ so any help is appreciated. Thanks in advance !
Finally got it to work:
IQueryable<File> dbfiles =
c.File.Where(f => f.Category.Any(cat => cat.name == categoryname) &&
f.alive &&
f.description == null &&
f.Category.Count == 1);

How can I embed optional Where parameters in a Linq to EF statement?

Let's say we have a description field on my form with optional check boxes. The check boxes represent which fields to search when doing the lookup. Right now I have a matrix of look ups that call their unique version of where clause. It works but I think it smells a bit.
Here is an excerpt
// Look for part numbers decide how many fields to search and use that one.
// 0 0 X
if (!PartOpt[0] && !PartOpt[1] && PartOpt[2])
{
query = query.Where(p => (p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum)));
}
// 0 X 0
if (!PartOpt[0] && PartOpt[1] && !PartOpt[2])
{
query = query.Where(p => (p.PartNumAlt.Contains(partSearchRec.inventory.PartNum)));
}
// 0 X X
if (!PartOpt[0] && PartOpt[1] && PartOpt[2])
{
query = query.Where(p => (p.PartNumAlt.Contains(partSearchRec.inventory.PartNum)
|| p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum)));
}
// X 0 0
if (PartOpt[0] && !PartOpt[1] && !PartOpt[2])
{
query = query.Where(p => (p.PartNum.Contains(partSearchRec.inventory.PartNum)));
}
. . .
This goes on for a while and seems to be prone to coding errors. In each case we are looking for the same information in any of the selected fields. If I was doing this in SQL I could simply build up the WHERE clause as needed.
Once again I rubber ducked my way to an answer. Rather than throw the question away, here is what I came up with. Is it efficient?
if (partSearchRec.optPartNum || partSearchRec.optAltPartNum1 || partSearchRec.optAltPartNum2)
{
query = query.Where(p => (
(partSearchRec.optPartNum && p.PartNum.Contains(partSearchRec.inventory.PartNum))
|| (partSearchRec.optAltPartNum1 && p.PartNumAlt.Contains(partSearchRec.inventory.PartNum))
|| (partSearchRec.optAltPartNum2 && p.PartNumAlt2.Contains(partSearchRec.inventory.PartNum))));
}
Basically if any of the check boxes are set we will execute the query. Each line of the query will be processed only if the check box was checked. If the left side of an AND is false it doesn't process the right.
This is an aera that Delphi's with statement would be handy. I also learned that you can't use an array inside the LINQ statement.