Ng-repeat in Sightly - angularjs-directive

I am trying to populate drop-down values using ng-repeat in Sightly. The AEM node saves my data as String array and I am able to fetch it properly, but not able to populate them as it throws "? undefined:undefined ?" error.
My code:
<select name="${validation.elementName}" id="${validation.elementName}" ng-model="${validation.elementName}" ng-change="${properties.clickfunction}">
<option ng-repeat="opt in ${properties.options}" value={{opt}}>opt</option>
</select>
And the output:
:
Is there anything I am missing? As Sightly is totally new to me. I will be very grateful for any help to improve this code or pointing my mistake.

First of all, you need to wrap the data you pass to value in quotes, so it should be like this:
value="{{opt}}"
Second, it looks like you are passing the values without single quotes and they are not being recognized as strings. Take a look at this plunker:
http://plnkr.co/edit/A2gZJbvVV9ozHloLkF4B?p=preview
You can see that the first ng-repeat works as expected, but the second throws an error in the console and doesn't display anything. Basically, you just need to put quotes around each string in your array.

Thanks #Victor for your reply.
Please find my below findings.
value="{{opt}}" was my mistake while pasting the code to stackoverflow.
${properties.options} returns string array.
ng-repeat seems to parse correctly as per this output.

Related

Complie Error: Method or Data Member not found, but it does exist

Having a strange problem in vba access. I have a text control control called txtUserName on a form and am trying to get the contents which is all but child's play. When I try to run or complie, I get the Method or Data Member not found error. However, when I type me. Intellisense shows txtUserName. I have gone as far as copying and pasting the name from the control's properties and still get the error. What am I missing? I am completely perplexed.
Thanks in advance
Don
In this case, I was just building a SQL string. I did find the problem, there was a bad control reference, however, it was not the one that was highlighted (highlighted was the first value in an insert into string and it was actually the 3rd value)

How to allow duplicates in ng-repeat?

I am using stringify and json is getting formatted and in alert it is coming.But in actual link it is not displaying. When I checked in console error was coming as "duplicates are not allowed in ng-repeat for the key".
Can anyone tell how to allow duplicates in ng-repeat so that formatted json will be printed.
Add 'track by $index' to the repeater.
https://docs.angularjs.org/error/ngRepeat/dupes

Saving values containing comma's in a HTML Multiple select

I have a HTML multiple select being used which caused no issue until a selection with a comma was entered. When saving / loading the values are split by ',' into a list. Therefore causing an issue
I have tried to find a way of possibly changing the character that is being used to split the values when the form is posted but came to a dead end.
Would be very grateful if someone has any insight into this.
Thanks in advance.
---Update with Code---
The control is created dynamically
Dim SelectName1 As New HtmlSelect
SelectName1.ID = "SelectName" & id
SelectName1.Name = "SelectName"
SelectName1.Multiple = True
and filled by looping though the values.
For Each value As String In Request.Form(idToFind).Split(",")
If Not IsDBNull(SelectName.Items.FindByValue(value)) Then....
I cannot add any more code than that, Apologies
After updating the question by add code, I think the available options are limited:
Create an extra Javascript method, that stores the selected values in a json object and store it into a hidden input field. I'm not an expert in asp.net, though I'm sure there exists a method to parse json objects from a string.
Create an extra javascript method, that concatinating all values to a String and store it into a hidden input field. With creation of a single string, you can define your own delimiter.
After that, add this extra Javascript mehod to the event onSubmit. Then submit the form and read the value from hidden input field.
P.S. In my eyes the second idea is more simple to create, than the first one. And maybe there are better ways.

How to check an array is exist or not?

I am new in java, I am developing an application, where I found some difficulties. Can anyone tell me how to check that an array is set or not, means the array is exist or not.
Actually I'm getting error when I run my jsp page which contains a listing of data with a HTML form. When I submit the form and get results it works fine, but very first time to open the page it doesn't get that resultant array and give the error.
Thanks in advance.
You should be checking if the array is empty or not like this:
<c:if test="${!empty array}">
//list the array
</c:if>
empty is an EL operator which return true if array is null or empty.
You can check whether a variable has been initialized or not by checcking if == null or not.

Is it possible to change the value of the query string when I click on a link?

I have a hyperlink with a query string like cgi-bin/filename.cgi?sort=ASC. When I click this link I want it to change its value to cgi-bin/filename.cgi?sort=DESC. And again when I click the link then it should go to its original query string state. Is it possible?
I had posted the same question previously, got an answer also which I have marked as accepted because I found that Jquery tablesorter solved my problem, but now there's a slight modification and I have been told to do it using the query string.
You're not changing the query string. Each time you sort your data, you're creating a new request to your script. When you use "sort=ASC" then the script's output should provide a link for "sort=DESC" and vice-versa.