I want to find the value of a parsed text in angular.
For example:
I know i can set the scope value of a variable text like following
var text = 'randomString';
$parse(text).assign($scope, 1234);
But i do not need to set the value. Instead i want to retrieve it. I tried console.log($parse('randomString')), but it prints out a function. I tried console.log($scope.$parse('randomString')), but it throws an error saying it is not a function.
I know i can use $scope.randomString in the above example but i need the string to be dynamic so i do not know what the string will actually be
How can i retrieve the value?
Okay so I came across a solution online. I used:
console.log($scope.$eval('randomString'));
Related
I am automating a page using selenium with java and trying to use a case insensitive xpath with the help of translate function as follows.
driver.findElement(By.xpath("//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'tools')]")).click();
'tools' text exists on the page as 'Tools'. [T as caps]
Now my question is,
What does '.,' means in the above code?
Using 'tools' in place of '.,' gives all the //a links. Reason?
Whenever I use 'Tools' instead of 'tools' in the above code, it does not work.
Someone help me here.
image 1
image 2
Now my question is,
What does '.,' means in the above code?
Using 'tools' in place of '.,' gives all the //a links. Reason?
Whenever I use 'Tools' instead of 'tools' in the above code, it does not work.
The dot step is an abbreviated syntax, from the specs:
. selects the context node
Because it's used as parameter for a function that expects a string, will be casted by the means of string() function.
The string 'tools' always contains the string 'tools', thus you are not filtering any selected a element when you used instead of .
In the other hand, any lowercase string will never contain the string 'Tools', so you won't be able to select anything.
My question lies in the following code. Though the code is not working now. I wan't to rewrite it in proper way so that it works.
<span ng-if="community = vm.getCommunity(invite.community_id)!=null" grv-icon-comm-type="vm.communityViewHelper.getTypeIcon(community)" ng-class="vm.communityViewHelper.getColorClass(community)"></span>
In the above code vm.getCommunity(invite.community_id) returns either null or community object. If community object is returned then I wish to call two more function in the same element where I wish to use the recently receivedcommunity value on those two function.
It's just killing my time. Please help.
Alternatively, you could use a watcher on "invite.community_id" to set community inside a controller function. Could look a bit cleaner depending on the rest of the code.
This function could even set all three values if you like.
I'm working with the hook_file_insert function and keep running into the same issue over and over again.
Let's take a look at the code:
function mymodule_file_insert($file) {
$src = $file->source // the file field a.k.a field_upload_und_0
file_save_upload($src, array(), 'public://styles/'); // <-- Here's where the issue is.
$file->description = 'Change desc value';
dsm($file) // debug
}
So basically when i upload a file i get this error:
The file MyDocument.doc could not be saved. An unknown error has occurred.
Other than that, I'm also trying to change the description value when the file is uploaded/saved. But that's not happening either. It does however, show as changed in the array when i look in the dsm results.
Am i misunderstanding this function? I suppose it only changes the files array and hangs on to. My thinking originally was that it modifies the actual field values but that doesn't seem to be the case.
How could i grab these values and pass them along in my hook_form_submit function? Is this possible?
Thanks,
The proper solution was to pass the $file variable by reference
function mymodule_file_insert(&$file) {...
I did a separate levelData class to be able to flexibly add levels. I was happy with it until my supervisor ordered me to convert my levelData into XML. I did an XML version of the levelData's data (question, answers, correct answer...). I used the old class and converted it so that it fetches the XML.
All seems well, I did traces of my answers array and it printed nicely...
But the headache started when I tried this.
// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
// BTW, I can't make a for loop to do the same function as above. So wierd.
I tried to run it. it returned:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at QuestionPane/setQuiz()
at QuestionPane/setQuestion()
at QuestionPane()
at LearningModule()
Where did I go wrong? I tried making a custom get function for it, only to get the same error. Thanks in advance. If I need to post more of the code, I will gladly do so =)
LevelData Class in PasteBin: http://pastebin.com/aTKC1sBC
Without seeing more of the code it's hard to diagnose, but did you correctly initialize the choices Array before using it? Failing that I think you'll need to post more code.
Another possible issue is the delay in loading the XML data. Make sure your data is set before QuestionPane tries to access it.
When did you call
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
these? You load the XML and on complete you fill the array, what is correct. but is the XML loaded and parsed to the time when you access (fill the TextFields) the choices array already?
I am trying to get a value from salesforce class into a javascript variable. I am able to get the value if its a single line value, but if its multiline textarea it gives a unterminated string literal error
caseUpdate.Description = "{!ac__c.C_Info__c}";
After googling for sometime i came to know we can have a workaround for this by having a hidden field and using DOM storing it using the document.getElement.Id. But i am calling this code on a button click so i would not be able to create a input text or hidden field value.
Any body who can provide an way to do it?
Thanks
Prady
You should just be able to use the standard Salesforce JSENCODE() function if you are using OnClick Javascript in a button. This will escape any characters for you.
See the documentation.
It is because of line breaks. merge fields are rendered unescaped into the output stream meaning that CRLFs push into a new line and break javascript strings. Either use the div/input trick or use Apex to replace \r\n's in the field with <br/> or whatever best suits the purpose. Also keep in mind that " will also terminate your JS string.
The easiest way is to just include a function in your extension and then you can use it across board
public String FixNewLine(String s) {
if (s != null) return s.replaceAll('\r\n', '<br/>').replaceAll('"', '\\"');
return null;
}
I had the same issue but was able to fix it! The trick is the JSENCODE function. Its basically {!JSENCODE(Obj.Field)}"; So you are replacing your merge field with this function and nesting the merge field itself within the function. In my scenario I ended up with opptyObj.Description="{!JSENCODE(Case.Description)}"; as my total syntax. First calling upon my set object and field, and then the merge data to populate it.