Hi Andrés, we will test this. It might take some time. Did you try it on another event?
Hi Andrés, we will test this. It might take some time. Did you try it on another event?
I have moved the code into Design - My page - Load - Run Javascript. I have enabled "console.log" and I see that the code is generated but isn't appended to "starsPanel".
The source code of the generated page is:
code<span name="starsPanel" dsid="starsPanel" id="j_96_0" class=" mobilepanel2" idx="0">
</span>/code
I've changed
codeinputText = ''; /code
for this other code:
codeinputText = '<input name="star1" type="radio" class="star" disabled="disabled"/>'; /code
but I suppose that, for each item, I will have to change "star1" for "star2", "star3", etc. don't you think?
I have changed from Event "Load" to "Page show" and now the code is written... but the stars aren't shown
I've fixed it!
I changed the code to:
codevar inputText, allInputs, starsNumb = 5, n = 1;
$("[dsid=starsPanel]").each(function(index){
inputText = '<input name="star' + n + '" type="radio" class="star"/>';
n++;
allInputs = '';
for (var i = 0; i < starsNumb; i++) {
allInputs += inputText;
}
$(this).append(allInputs);
});
$(".star").rating();/code
I still haven't finished with this yet.
I need to assign a value to the star rating, read from a JSON.
What I've done is to create a label element (regaloNota), and assign the value of the JSON to it. I've seen that the label acquires the correct value of each item in the JSON (I have about 10 items, each one with its regaloNota value).
Now the problem is to read that value by Javascript. I've created this code:
codevar inputText, inputChecked, allInputs, starsNumb = 6, n = 1;
$("[dsid=starsPanel]").each(function(index){
var regalo_nota = Appery("regaloNota").val();
console.log("regalo_nota val:", regalo_nota);
inputText = '<input name="star' + n + '" type="radio" class="star"/>';
inputChecked = '<input name="star' + n + '" type="radio" class="star" checked="checked"/>';
n++;
allInputs = '';
for (var i = 1; i < starsNumb; i++) {
allInputs += ((regalo_nota == i) ? inputChecked : inputText);
}
console.log("allInputs", allInputs);
$(this).append(allInputs);
});
$(".star").rating();/code
The console shows that regalo_nota is empty (even that the value is shown by the label component).
I thave tried also this:
codevar regalo_nota = Appery("regaloNota").text();/code
but I see it empty also.
What's wrong?
Hi Andrés.
We'll test this and update.
Any news?
Hello Andrés - we are sorry for the delay.
We are still working on it, hope tomorrow will be some news.
Hi Andrés.
It's clear now what you want to do. There is easier way to do this.
1) Delete code we suggested to you from Page show
2) Add to JS file with rating plugin (or just create new JS file) this code:
var currRatingId = 0;
3) assign the value of the JSON to starsPanel-HTML code and add JS code to this mapping:
precode
var inputText, inputChecked, allInputs, starsNumb = 6;
inputText = '<input name="star' + currRatingId + '" type="radio" class="star"/>';
inputChecked = '<input name="star' + currRatingId + '" type="radio" class="star" checked="checked"/>';
currRatingId++;
allInputs = '';
for (var i = 1; i < starsNumb; i++) {
allInputs += ((value == i) ? inputChecked : inputText);
}
return allInputs;
/code/pre
4) On service Success event add Run JavaScript code:
$(".star").rating();
5) And finally add this JS code before service invoke (on Events tab use arrowUp icon to move code before service invoke):
currRatingId = 0;
Hello Oleg.
Your solution worked, thank you very much!
Today I've learned a new way of getting the value, instead of using Appery("element").val(); in this case it had to be "value" right from the JSON data.