Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus
Accepted Solution

IF statement thinks 99 is larger than 658

I have a sheet that is setup to show a toast and prevent the user from saving the data if the value in textbox 1 is equal to or larger than texbox 2.  Unfortunately it looks like the funciton is only looking at the first number in each value to determine this.  I.e. if i input 99 in textbox 1 and 657 in textbox 2, it'll say textbox one is larger than textbox 2.

 

onTriggered: {
                                                                            
                                 
                          if (counter.text >= limittwo.text && limittwo.text !=0)
                           {
                            editlimitToast.show();
                              }
                           else
                             {
                                                                            rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, name2.text, ListItemData.description, datefield2.text, counter.text, limittwo.text, ListItemData.categorySelect, ListItemData.mapurl);
                            editSheet.close()
                            editToast.show()
                               }
                                                                            
                           }

 

 

any help would be greatly appreciated and likes/ solutions will be given.

Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: IF statement thinks 99 is larger than 658

found a solution.  one must parse the number value fields so that they get noticed as intergers instead of text:

 

onTriggered: {
                                                                            
                                 
                          if (parseInt(counter.text) >= parseInt(limittwo.text) && parseInt(limittwo.text) !=0)
                           {
                            editlimitToast.show();
                              }
                           else
                             {
                                                                            rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, name2.text, ListItemData.description, datefield2.text, counter.text, limittwo.text, ListItemData.categorySelect, ListItemData.mapurl);
                            editSheet.close()
                            editToast.show()
                               }
                                                                            
                           }

 

Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: IF statement thinks 99 is larger than 658

Maybe you should create a variable for each first, before trying to compare.

 

var counterValue = parseInt(counter.Text)
var limitTwoValue = parseInt(limittwo.Text)

if ((counterValue >= limitTwoValue) && (limitTwoValue != 0)) {...

 

Or, check the limitTowValue compare first and then do an if for the second check

 

if(counterValue >= limitTwoValue) {
     if(limitTwoValue !=0) {
        // do action for limitTwo
     } else {
        // do normal action
     }
} else {
    // do normal action
}

 

 

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: IF statement thinks 99 is larger than 658

Also be very careful parsing user supplied input. In this case, if a user were for example to supply text with a leading 0, the value would be parsed as an octal representation of the number rather than a decimal one as you probably intended.

You can use parseInt(theText, 10) to handle that particular case, but you should also make sure to handle cases where there is other invalid input, like a real number (3.14159) or non-numeric data, assuming your input field validation doesn't already prevent that.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: IF statement thinks 99 is larger than 658

Thanks guys.  I didn't even think of that!