Koning Voetbal
Posts: 0
Joined: Thu Feb 27, 2014 2:21 pm

How to het the label value in a list item?

Hi,

I have a list with multiple items from a database.

I get from the database a value, e.g. -0.1234, and get this value in a label, e.g. list_label_enkel_text.

So far so good, the value -0.1234 is displayed in the app.

But now I want to make the color of the font red if it's a negative value and green if it's a positive value.

I think I can give this a try with this:

code
var x = 'some string';
alert(x.charAt(0)); // alerts 's'
/code

This will give me in the alert 's' so I can make an if ... else construction if the first character is '-' to get the color of the font red.

But I can't get the value of the label in an alert.

I tried the following, all resulting in an empty alert:

code
var input = Apperyio('list_label_enkel_text');
alert(input.text());

var x2 = Apperyio('list_label_enkel_text').text();
alert(x2);

alert(Apperyio('list_label_enkel_text').text());
/code

I set these alerts btw in the Success Mapping, as shown in the image below.

Image

Any idea how to get it done?

Kind regards,

Arie

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to het the label value in a list item?

Hi Arie,

please try following:

  1. Click on "JS" for link to "list_label_enkel_text" label.
    Details: http://prntscr.com/6zcxpz/direct

  2. JS editor will appear.

  3. Populate it with following JS code:

    pre

    var val = parseFloat(value);

    //Condition to negative value.
    if(val < 0){
    element&#46;css("font-color", "#f00");
    };

    return value;

    /pre

    Regards.

Koning Voetbal
Posts: 0
Joined: Thu Feb 27, 2014 2:21 pm

How to het the label value in a list item?

Hi Yurii,

Tnx for clearing this out for me with the element.css in stead of Apperyio('label_name').text(). It works like a charm now ;-)

Making the value a float was also a good solution.

The only thing I had to change was the style "font-color", changing it to "color" did the trick.

Kind regards,

Arie

Return to “Issues”