Edit the selected option text in "ng-options" select-list - angularjs

I need to add the text "(Default)" to the selected-option text. please help me...
The text should be "Visa 1881 (Default)".
But its only showing "Visa 1881". Here is my code:
<select ng-options="item.brand + ' ' + item.last_digits for item in approvedinvoicesCtrl.current_job.cards" ng-model="approvedinvoicesCtrl.GetCard"></select>
var vmc = this;
vms.current_job = response.data.payment_info;
for (var i = 0; i < vmc.current_job.cards.length; i++){
if (vmc.current_job.cards[i].is_default){
vmc.GetCard = vmc.current_job.cards[i] + ' (Default)';
}
}
What I get is this,
And what I need is this.
Thanks.

Try to initialize using ng-init default value:
<select ng-init=" approvedinvoicesCtrl.GetCard = initialValue"
ng-model="approvedinvoicesCtrl.GetCard"
ng-options="item.brand + ' ' + item.last_digits for item in approvedinvoicesCtrl.current_job.cards">
</select>
Updated:
jsfiddle link:
https://jsfiddle.net/avnesh2/g2j6863a/6/
working as you want.
Hope this will work.

In your if() statement, you're assigning a value to cards[i].is_default instead of evaluating it. So not only your condition will always be true , cards[i].is_default value will also be (String) "true".
if (this.current_job.cards[i].is_default = 'true')
// Should be
if (this.current_job.cards[i].is_default == 'true')
You should use == instead of =.
Do you want the option text to be Visa 1881 (Default) instead of Visa 1881?
In this case you can just add a string to the value:
this.GetCard = this.current_job.cards[i] + ' (Default)';

Related

How to write a 2D array to a single column in Google Sheets, using Google Apps Script?

I'm trying to write the array to a single column, but despite everything seems right to me, it keeps throwing me an error:
Here's the piece of code:
function getGFTickersData() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LIST OF STOCKS");
var tickerRng = ss.getRange(2, 1, ss.getLastRow(), 1).getValues();
//var TDSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TickersData");
var TDSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet10");
var tickerArr = [];
for (var b = 0; b < tickerRng.length; b++) {
var tickerToArr = [tickerRng[b]];
if (tickerToArr != '') {
var gFinFormula = "=query(googlefinance(" + '"' + tickerToArr + '"' + ",'all shares'!A4,'all shares'!D3,'all shares'!D4,'all shares'!D5)," + '"' + "select *" + '"' + ",1)";
var repeated = [].concat(... new Array(105).fill(tickerToArr))
tickerArr.push(repeated)
}
}
Logger.log(tickerArr[0]);
TDSheet.getRange(TDSheet.getLastRow() + 1, 1, tickerArr.length, 1).setValues(tickerArr);
}
Appreciate any pointers!
From your following replying,
The array is composed of about 200k element, each showing in the array 105 times. I want to write all of them, one on the top of the other in a single column.
How about the following modification?
From:
tickerArr.push(repeated)
To:
tickerArr = tickerArr.concat(repeated);
References:
push()
concat()

Concatenate a character to a TextBox value

How to concatenate a character after the field value in a text box in Telerik Reporting?
I tried the below way. Its not working. Is there any way to achieve this task?
= {Fields.OlderThan} + " Days"
= {Fields.OlderThan} + Days
= {Fields.OlderThan} Days
textBox24.Value expression [= {Fields.OlderThan} "Days"] is not valid:
If Fields.OlderThan = 10
Result should be "10 Days"
You should get rid of those {}. It should work just fine without them: = Fields.OlderThan + " Days".
I also like to handle the case where the field might be null, because if Fields.OlderThan is null nothing will get printed in your text box:
= IsNull(Fields.OlderThan,"") + " Days"

md-select default value with condition

i'm using md-select to pick a year there is a scenario that when you fill up the form in the first time you will get a default value of latest year else you will get the previous value.
here's my view(slim format)
md-input-container flex=""
label Year
md-select name="type" ng-model="detail.year" ng-change="addYear(detail.product_id)"
md-option ng-repeat="year in years" value="{{year.year}}" ng-selected="detail.year? == null ? year.year : $first"
| {{year.year}}
and here's my controller for iterate the year (coffee format)
$scope.years = []
start_year = (new Date).getFullYear()
i = start_year
while i >= 2005
$scope.years.push(year: i)
i--
my error
putting comment as answer...
ng-selected="detail.year? == null ? year.year : $first" | {{year.year}}
don't add logic in html, keep it in JS files, it will be more easily testable + you dont have to fight with angular syntax support

AngularStrap Typeahead randomly selects the display value instead of model value

I am using AngularStrap's Typeahead directive in several dropdowns and sometimes, the display value shows up as the selected value.
For example, if I want to show just the number as the selected value in the input field, sometimes both the number and the description are selected. Here is the relevant code :
<input type="text" class="form-control"
bs-typeahead
bs-options="x.num as (x.num > 0 ? x.num + '. ' + x.Description : '')for x
in crc.xList | orderBy: 'x.num'"
data-autoSelect="true"
data-limit="15"
ng-model="crc.newNum"
ng-model-options="{ debounce: 500 }"
ng-change="crc.getNumInfo(false, true)" />
Any help would be appreciated - thanks!
I think it is because of (x.num > 0 ? x.num + '. ' + x.Description : ''), I think angular replaces the empty string when x.num is 0 to the value, could you try to do (x.num > 0 ? x.num + '. ' + x.Description : 'test') instead and see if it fixes it ?

Regex for picking up a color name from HTTP response

I am using Loadrunner and need to come up with a regex that will pick up a particular word from the HTTP response coming in and save it in a parameter.
The response looks like this:
\t\t\t\t\t<option value="Rose taupe" id="WD26" class="WD26">Rose taupe</option>\n
\t\t\t\t\t<option value="Myrtle" id="WD20" class="WD20">Myrtle</option>\n
\t\t\t\t\t<option value="Deep carmine pink" id="WD142" class="WD142">Deep carmine pink</option>\n
\t\t\t\t\t<option value="Wild Strawberry" id="WD66" class="WD66">Wild Strawberry</option>\n
\t\t\t\t\t<option value="Cream" id="WD72" selected="selected" class="WD72">Cream</option>\n
\t\t\t\t\t<option value="Tangerine yellow" id="WD94" class="WD94">Tangerine yellow</option>\n
I want to pick up the color that is selected in a drop down menu in the front end, in the response this color line has selected="selected" in it. This is however random for each instance hence the regex has to pickup the color name from the line which contains selected="selected".
I then have to use it in my script as follows:
web_reg_save_param_regexp ("ParamName=SelectedColor",
"RegExp=-regular expression here-",
"Ordinal=All",
LAST);
Thank you for your help!
The RegExp /<\s*option\s+(?=.*selected\s*=).*value\s*=\s*(?:"([^"]*)"|'([^']*)')/g will match the option tag with the selected attribute. The order of attributes is arbitrary. If attribute quotes may be ' then you need to handle the second match group, see example.
var s = '\t\t\t\t\t<option value="Rose taupe" id="WD26" class="WD26">Rose taupe</option>\n' +
'\t\t\t\t\t<option value="Myrtle" id="WD20" class="WD20">Myrtle</option>\n' +
'\t\t\t\t\t<option value="Deep carmine pink" id="WD142" class="WD142">Deep carmine pink</option>\n' +
'\t\t\t\t\t<option value="Wild Strawberry" id="WD66" class="WD66">Wild Strawberry</option>\n' +
'\t\t\t\t\t<option value="Cream" id="WD72" selected="selected" class="WD72">Cream</option>\n' +
'\t\t\t\t\t<option id="WD72" value=\'Cream\' selected="selected" class="WD72">Cream</option>\n' +
'\t\t\t\t\t<option value="Tangerine yellow" id="WD94" class="WD94">Tangerine yellow</option>\n';
var re = /<\s*option\s+(?=.*selected\s*=).*value\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
var m;
while (m = re.exec(s)) {
console.log("Selected color: " + (m[1]||m[2]) + ", match " + m[0]);
}
Below code will work.
web_reg_save_param_ex(
"ParamName=SelectedItem",
"LB/IC/DIG=id=\"^^^^\" selected=\"selected\"",
"RB=</option>",
"Ordinal=1",
SEARCH_FILTERS,
"Scope=ALL",
LAST);

Resources