Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Working with plugins

Hi Andrés, we will test this. It might take some time. Did you try it on another event?

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

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">
<&#47;span>/code

I've changed
codeinputText = ''; /code
for this other code:
codeinputText = '<input name="star1" type="radio" class="star" disabled="disabled"&#47;>'; /code
but I suppose that, for each item, I will have to change "star1" for "star2", "star3", etc. don't you think?

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

I have changed from Event "Load" to "Page show" and now the code is written... but the stars aren't shown :-?

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

I've fixed it!

I changed the code to:
codevar inputText, allInputs, starsNumb = 5, n = 1;
$("[dsid=starsPanel]")&#46;each(function(index){
inputText = '<input name="star' + n + '" type="radio" class="star"&#47;>';
n++;
allInputs = '';
for (var i = 0; i < starsNumb; i++) {
allInputs += inputText;
}
$(this)&#46;append(allInputs);
});
$("&#46;star")&#46;rating();/code

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

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]")&#46;each(function(index){
var regalo_nota = Appery("regaloNota")&#46;val();
console&#46;log("regalo_nota val:", regalo_nota);
inputText = '<input name="star' + n + '" type="radio" class="star"&#47;>';
inputChecked = '<input name="star' + n + '" type="radio" class="star" checked="checked"&#47;>';
n++;
allInputs = '';
for (var i = 1; i < starsNumb; i++) {
allInputs += ((regalo_nota == i) ? inputChecked : inputText);
}
console&#46;log("allInputs", allInputs);
$(this)&#46;append(allInputs);
});
$("&#46;star")&#46;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")&#46;text();/code
but I see it empty also.

What's wrong?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Working with plugins

Hi Andrés.

We'll test this and update.

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

Any news?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Working with plugins

Hello Andrés - we are sorry for the delay.

We are still working on it, hope tomorrow will be some news.

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Working with plugins

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"&#47;>';
inputChecked = '<input name="star' + currRatingId + '" type="radio" class="star" checked="checked"&#47;>';
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;

Andrés Méndez
Posts: 0
Joined: Thu Apr 18, 2013 6:13 pm

Working with plugins

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.

Return to “Issues”