I wanted to hide Optionset values on Field Service - Dynamics 365 app. We are doing customizations using Woodford Solution. Based on Resco Javascript Bridge Reference, I see no methods to hide options in existing Option Set. So I created a ComboBox and tried to add Options into ComboBox. But it is showing only one single option even if I add multiple options that too with the wrong Label on ComboBox.
if ((responseTypeOptionSetValues.length == responseTypeOptionSetLables.length)
&& responseTypeOptionSetLables.length > 0) {
for (i = 0; i < responseTypeOptionSetValues.length; i++) {
if (valueListOptions.length > 0) {
for (i = 0; i < responseTypeOptionSetValues.length; i++) {
if (valueListOptions.indexOf(responseTypeOptionSetValues[i].toString()) != -1) {
finalLabelValue = responseTypeOptionSetLables[i].toString();
finalOptionValue = responseTypeOptionSetValues[i].toString();
comboItem.listDataSource = {
**finalLabelValue: finalOptionValue,**
};
}
}
}
}
}
var data = new Object();
if ((responseTypeOptionSetValues.length == responseTypeOptionSetLables.length) && responseTypeOptionSetLables.length > 0) {
for (i = 0; i < responseTypeOptionSetValues.length; i++) {
if (valueListOptions.indexOf(responseTypeOptionSetValues[i].toString()) != -1) {
finalLabelValue = responseTypeOptionSetLables[i].toString();
finalOptionValue = responseTypeOptionSetValues[i].toString();
data[finalLabelValue] = finalOptionValue;
}
}
}
if (!isComboItemExists) {
comboItem.listDataSource = data;
detailView.insertItem(comboItem, -1);
}
else {
comboItem.listDataSource = data;
}
You're nesting your loops with the same variable name. Give each loop a unique variable: i, j, k...
Related
In a GridView, the name of the table is getting generated dynamically. but it will have the dynamic Name with GridView ID gets appended.
something Like "w123443dsfnsbd32dkkd_GridView1". so first part will always keep changing whenever we reloads the grid. so I would like to get the name of the Grid with "_GridView1", with this I would like to fetch the complete Grid Name. So Is there a way to look for this?
I tried this var table = document.getElementById("GridView1"); but didn't work.
Code:
var table = document.getElementById("wcwidget_df5339c463eedb_widget_gridView1");
if (table.rows.length > 0) {
for (var i = 0 ; i < table.rows.length; ++i) {
if (table.rows[i].cells[0].innerText == "Company1" || table.rows[i].cells[0].innerText == "Company2" ||
table.rows[i].cells[0].innerText == "Company5" )
{
for (var k = 1; k < table.rows[i].cells.length; ++k) {
table.rows[i].cells[k].style.fontWeight = "bold";
table.rows[i].cells[k].style.color = "black";
}
}
}
for (var i = 0 ; i < table.rows.length; ++i) {
if (table.rows[i].cells[0].innerText == "Risk" || table.rows[i].cells[0].innerText == "Medium Risk" || table.rows[i].cells[0].innerText == "High Risk" ) {
table.rows[i].cells[0].style.fontWeight = "bold";
table.rows[i].cells[0].style.color = "black";
}
}
}
try this:
document.querySelectorAll("[id*='GridView1']")
this will return an array.
On modern browsers see the #amit's answer.
If compatibility with older browsers is required:
var allElements = document.getElementsByTagName("*");
for (var i = 0, n = allElements.length; i < n; ++i) {
var element = allElements[i];
if (element.id.endsWith("_GridView1")) {
// do something with the found element
break;
}
}
I am able to search and display the results that the user is typing on the keyup function. But now when the results show up inside my <div> tag, they are not clickable. Is there a way I can make them clickable and also allow the user to select multiple results from the live search results. This is what I tried so far.
HTML
<input type="text" id ="medication" name="medication" onkeyup="getsearch(this.value)"><br>
<div id="livesearch"></div>
JavaScript
function getsearch(val) {
results = [];
document.getElementById("livesearch").innerHTML = "";
if (val.length == 0) {
document.getElementById("livesearch").innerHTML = "";
document.getElementById("livesearch").style.border = "0px";
return;
}
console.log(s);
console.log("val", val);
if (val.length > 2) {
for (var i = 0; i < s.length; i++) {
for (key in s[i]) {
if (s[i][key].indexOf(val) != -1) {
$("#livesearch").append(s[i][key]);
$("#livesearch").append("<br/>");
results.push(s[i]);
}
}
}
}
console.log(results);
};
There are some other thing I would do differently here, but as far as what you are looking to do this should work.
if(val.length>2) {
for (var i = 0; i < s.length; i++) {
for (key in s[i]) {
if (s[i][key].indexOf(val) != -1) {
var newDom = $('<div><\div>'); //create a DOM element to wrap each of the return text in.
newDom.text(s[i][key]);
$("#livesearch").append(newDom);
results.push(s[i]);
}
}
}
}
Then you can assign the click event to you dynamically created DOM this way.
$('#livesearch').on('click', 'div', myDoStuffFunc);
function myDoStuffFunc(){
// this is fired from the click event
}
Here is the code I am trying to remove the redundant code and move the code to separate function.
//Adding Infotypes to filter and checks whether any infotype option is selected
if(this.$infoOptions.val() != null){
var infotypelength = this.$infoOptions.val().length;
var l=0,j;
//Condition to check empty input type
if( infotypelength > 0){
var infotypeList = this.$infoOptions.val();
for(j = 0; j < infotypelength; j++) {
//It checks whether already option is selected and prevents adding to filter if its duplicate.
if(($.inArray( $('#infoOptions').select2('data')[j].text, filterList)) == -1 ){
this.filter.push($('#infoOptions').select2('data')[j].text);
if(infotypeList[j].contains('_subgroup')){
var res = infotypeList[j].split("_");
this.aSubinfotype[l]=res[0];
l=l+1;
}
else
this.aInfotypes.push(infotypeList[j]);
}
}
}
}
//Adding Countries to filter
if(this.$countryOptions.val() != null){
var geoLength = this.$countryOptions.val().length;
//Condition to check empty input type
if( geoLength > 0){
var geoList = this.$countryOptions.val();
var l=0;
for(var j = 0; j < geoLength; j++) {
if(($.inArray( $('#countryOptions').select2('data')[j].text, filterList)) == -1 ){
this.filter.push($('#countryOptions').select2('data')[j].text);
if(geoList[j].contains('_subgroup')){
var res = geoList[j].split("_");
this.aSubgeotype[l]=res[0];
l=l+1;
}
else
this.aGeography.push(geoList[j]);
}
}
}
}
But I am facing problem in passing the variable and cached selectors in to other function. Can anyone help me with this?
I don't know how is done your implementation but I really think that you can improve it, by the way, you can reduce your code in two way bit different :
var myFunction = function(option, filter, array, selector, subType) {
if(option && option.val()){
var optList = option.val();
var optLength = optList.length;
//Condition to check empty input type
if( optLength > 0) {
var l = 0;
for(var j = 0; j < optLength; j++) {
if( ($.inArray( selector.select2('data')[j].text, filterList)) == -1 ){
filter.push(selector.select2('data')[j].text);
if(optList[j].contains('_subgroup')){
var res = optList[j].split("_");
subType[l]=res[0];
l=l+1;
} else {
array.push(optList[j]);
}
}
}
}
}
}
call : myFunction(this.$countryOptions, this.filter, this.aGeography, $('#countryOptions'), this.aSubgeotype)
// data = {option, filter, array, selector, subType}
var myFunction = function(data) {
if(data.option && data.option.val()){
var optList = data.option.val();
var optLength = optList.length;
//Condition to check empty input type
if( optLength > 0) {
var l = 0;
for(var j = 0; j < optLength; j++) {
if( ($.inArray( data.selector.select2('data')[j].text, filterList)) == -1 ){
data.filter.push(data.selector.select2('data')[j].text);
if(optList[j].contains('_subgroup')){
var res = optList[j].split("_");
data.subType[l]=res[0];
l=l+1;
} else {
data.array.push(optList[j]);
}
}
}
}
}
}
call :
myFunction({
option: this.$countryOptions,
filter: this.filter,
array: this.aGeography,
selector: $('#countryOptions'),
subType: this.aSubgeotype
});
or
var data = {
option: this.$countryOptions,
filter: this.filter,
array: this.aGeography,
selector: $('#countryOptions'),
subType: this.aSubgeotype
}
myFunction(data);
The first way is to pass your data one by one, the second you pass your data into an json object.
I have set filter in Kendo grid but i have a problem when filter applied to grid, i missed value of my filter row.
After filter i missed my filter :
Now for this reason, i set my filter row again so bellow code :
function updateSearchFilters(grid, field, operator, value)
{
var newFilter = { field: field, operator: operator, value: value };
var dataSource = grid.dataSource;
var filters = null;
if ( dataSource.filter() != null)
{
filters = dataSource.filter().filters;
}
if ( filters == null )
{
filters = [newFilter];
}
else
{
var isNew = true;
var index = 0;
for(index=0; index < filters.length; index++)
{
if (filters[index].field == field)
{
isNew = false;
break;
}
}
if ( isNew)
{
filters.push(newFilter);
}
else
{
//alert(value);
if(value == '')
filters.splice(index,1);
//delete filters[index];
else
filters[index] = newFilter;
}
}
dataSource.filter(filters);
for (var i = 0; i < filters.length; i++) {
$('#gridId-filter-column-' + filters[i].field.toString()).val(filters[i].value.toString());
}
}
When i set the break point in this line $('#gridId-filter-column-' + filters[i].field.toString()).val(filters[i].value.toString()); it worked correct but
when i remove break point this line doesn't work.
you can set delay before run this line :
for (var i = 0; i < filters.length; i++) { $('#gridId-filter-column-' +filters[i].field.toString()).val(filters[i].value.toString()); }
I'm putting down markers via the Google Maps API based on checkboxes. I want the map to show only markers that are the intersection of all checked checkboxes.
I have function getCheckedBoxes(chkboxName) which will return an array containing the IDs of all checkedBoxes.
Function show displays markers based on whether they have that ID inside of one of their category properties.
function show(category, type) {
var checkedBoxes = getCheckedBoxes("checkbox");
if (checkedBoxes !== null) {
for (var i=0; i<checkedBoxes.length; i++) {
for (var n=0; n<gmarkers.length; n++) {
if (gmarkers[n][category].toUpperCase().indexOf(checkedBoxes[i].toUpperCase()) !== -1) {
gmarkers[n].setVisible(true);
}
}
}
}
// == check the checkbox ==
document.getElementById(type+" box").checked = true;
}
the problem line is obviously if (gmarkers[i][category].toUpperCase().indexOf(checkedBoxes[i].toUpperCase()) !== -1) which will cause the markers to be plot if it is satisfied only once. I need something like Python's all to ensure that 'TRUE' has to appear for every iteration.
Any ideas?
Dr. Molle suggested using every, but I can't seem to think of how it would work. Something like this?
function insideChecked(marker, category) {
var checkedBoxes = getCheckedBoxes("checkbox");
for (var i=0; i<checkedBoxes.length; i++) {
if (marker[category].toUpperCase().indexOf(checkedBoxes[i].toUpperCase()) == -1) {
return false;
}
return true
gmarker.every(insideChecked); ?
I solved it with this, but I would still like to know a better way to solve this issue:
function show(category, type) {
var tracker = 0;
var checkedBoxes = getCheckedBoxes("checkbox");
for (var i=0; i<gmarkers.length; i++) {
if (checkedBoxes !== null) {
for (var n=0; n<checkedBoxes.length; n++) {
if (gmarkers[i][category].toUpperCase().indexOf(checkedBoxes[n].toUpperCase()) !== -1) {
//found a match
tracker+=1;
}
}
}
if (tracker == checkedBoxes.length) {
gmarkers[i].setVisible(true);
tracker = 0;
}
else {
gmarkers[i].setVisible(false);
tracker = 0;
}
}
}