Results 1 to 15 of 15
  1.    #1  
    Ugh, been trying all night to no avail, so I turn to you wise WebOS devs to hopefully bail me out again.

    I have 4 buttons. My goal is to assign the buttons a value. Then I'd have a single handler for all 4 buttons. I pictured the handler being called and then doing something like

    Code:
    MainAssistant.prototype.handleButtonPress = function(event){
    myValue = event.value
    }
    But I simply cannot get that to work. Even after defining value in my model I just get undefined for event.value.

    Any help would be appreciated.

    Thanks!!!
  2. #2  
    In your button listener function do you have:

    Code:
    this.handleButtonPress.bind(this);
    as your callback?
  3. #3  
    On the Palm dev web site, I don't see "value" as being a valid model property, so I'm not sure this is possible. Why not just have 4 separate event handlers? If they will be performing common tasks, just have the event handlers call a common routine.
  4.    #4  
    This is my listener call:
    Code:
    Mojo.Event.listen(this.controller.get('button-1'), Mojo.Event.tap, this.handleButtonPress.bind(this));
    I saw that it wasn't a property, but to be honest I was a little confused. I thought I saw you could sort of overload in a sense by defining modelProperty:'value' in the properties, but I very well could be wrong.

    I figured I could cheat by using the name field as a value field, but I get undefined on that as well.

    The 4 buttons are going to be dynamic of a sort based on preferences. Each button needs to have a numeric value but I don't want the label to be a number. I guess I could create 4 handlers and in the preference cookie or whatever I end up doing I can just have button-1 = 6, button-2=12 or whatever and sort of hard code looking up the preference in the handler. I just thought giving the button a value would be a bit more elegant.

    Thanks for the guidance guys!
  5.    #5  
    While I hopefully have a slice of your attention, what would you think is the best method for storing preferences? I plan on having a sqllite DB for my data. Should I use that for preferences or a cookie or a depot?

    Thanks!
  6. moserjj's Avatar
    Posts
    468 Posts
    Global Posts
    470 Global Posts
    #6  
    one thing i've done when i'm not sure what is being returned to the function is do something like:

    Code:
    MainAssistant.prototype.handleButtonPress = function(event) {
         Mojo.Controller.errorDialog(Object.toJSON(event));
    }
    Once you see the results, you should be able to determine how to get your value
  7. moserjj's Avatar
    Posts
    468 Posts
    Global Posts
    470 Global Posts
    #7  
    Quote Originally Posted by nyquistJack View Post
    While I hopefully have a slice of your attention, what would you think is the best method for storing preferences? I plan on having a sqllite DB for my data. Should I use that for preferences or a cookie or a depot?

    Thanks!
    i use cookies for storing preferences myself
  8. #8  
    Come to think of it, that's true. I don't think button's have "values". Sorry!

    I know you can get whatever is pressed by doing something like "event.id" and looking at that. You could try something like... "event.id.value"... haha cuz that starts looking at the HTML of your button. So maybe you want to have an attribute in the HTML of "value=0" or whatever... I don't know >.<.
    Play around with it!

    And yes, cookies for preferences. I'm scared of jumping into DB's. >.<
  9. #9  
    I'm using a Depot for preferences myself, I created a simple wrapper around it for getting/setting and resetting the database, and in my case I wanted to know if 'X' and 'Y' were set, if not show a 'first time' screen and otherwise goes to the main screen.. Don't know if that was the best approach but it works for me. I will use an actual database for real data as a Depot does have a storage limit.
    My Palm History (in order): IIIe SE, m130, Tungsten|T, m505, Tungsten|T3, Zire 71, m505 (owned two different ones), Zire 72, Tungsten|C, T|X, Treo 650.
    After that I got a Apple iPhone 3G, Palm Pre (GSM), Google Nexus One.
  10.    #10  
    It looks like using individual handlers + a preferences cookie will do the trick. Boy are cookies nice and easy!!! I likes them precious.

    Is there any IRC channel or anything that all you wonderful devs hang out on? It's amazing how quickly just a little nudge from you guys gets me in the right direction.

    Another thing I am trying is to change the color of buttons. Only thing I've found is applying an image to the background of a button, but I just want a solid color.

    Again, thanks a ton!
  11. #11  
    Have you tried putting the numbers in between the div tags in the view file, then pulling the values?

    View File...
    Code:
    <div id="button1" x-mojo-element="Button">1</div>
    <div id="button2" x-mojo-element="Button">2</div>
    <div id="button3" x-mojo-element="Button">3</div>
    <div id="button4" x-mojo-element="Button">4</div>
    Not sure if that will work (getting the value part) but I do know that placing the numbers in between the div tags won't change the appearance of your button.

    OR: if "event.buttonLabel" works you can try something like this in your handler...

    Code:
    if (event.buttonLabel == 'Button Label 1') {value = 1;}
    else if (event.buttonLabel == 'Button Label 2') {value = 2;}
    else if (event.buttonLabel == 'Button Label 3') {value = 3;}
    else if (event.buttonLabel == 'Button Label 4') {value = 4;}
    Not sure if these will work, just suggestions...
    Last edited by Laxidasical; 11/18/2009 at 06:06 AM.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  12. #12  
    Oh yeah...I recommend the SQLite DB for preferences. The Depot uses the SQLite DB anyway, it's just a way off accessing it without knowing (or wanting to use) SQL statements. I forget where (I believe it was in the O'Reilly book), but I remember reading that the Depot has considerable overhead compared to accessing SQLite directly, especially if you are dealing with a lot of data and your schema isn't ULTRA simple.

    SQLite & Depot data will survive app closing/reopening as well as app updates. I believe cookie data is destroyed when an app closes. If that is the case, you should definitely use one of the former for preferences.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  13.    #13  
    Quote Originally Posted by Laxidasical View Post
    Have you tried putting the numbers in between the div tags in the view file, then pulling the values?

    View File...
    Code:
    <div id="button1" x-mojo-element="Button">1</div>
    <div id="button2" x-mojo-element="Button">2</div>
    <div id="button3" x-mojo-element="Button">3</div>
    <div id="button4" x-mojo-element="Button">4</div>
    Not sure if that will work (getting the value part) but I do know that placing the numbers in between the div tags won't change the appearance of your button.

    OR: if "event.buttonLabel" works you can try something like this in your handler...

    Code:
    if (event.buttonLabel == 'Button Label 1') {value = 1;}
    else if (event.buttonLabel == 'Button Label 2') {value = 2;}
    else if (event.buttonLabel == 'Button Label 3') {value = 3;}
    else if (event.buttonLabel == 'Button Label 4') {value = 4;}
    Not sure if these will work, just suggestions...
    Not sure what I was doing wrong but I did try event.buttonLabel and event. a bunch of other things and it wasn't working. I ended getting so hyperfocused on it I ignored more obvious solutions.

    I ended up doing a handler per button and using preferences. I am using a cookie right now just because they are shockingly easy, but it gets defined every time I run it so I don't know if it gets wiped out yet but I am pretty sure they don't. I will be trying that soon though and will happily report back.

    Thanks for the suggestions!
  14.    #14  
    Quote Originally Posted by Laxidasical View Post
    Oh yeah...I recommend the SQLite DB for preferences. The Depot uses the SQLite DB anyway, it's just a way off accessing it without knowing (or wanting to use) SQL statements. I forget where (I believe it was in the O'Reilly book), but I remember reading that the Depot has considerable overhead compared to accessing SQLite directly, especially if you are dealing with a lot of data and your schema isn't ULTRA simple.

    SQLite & Depot data will survive app closing/reopening as well as app updates. I believe cookie data is destroyed when an app closes. If that is the case, you should definitely use one of the former for preferences.
    You made me realize something. I am considering writing a simple wrapper around SQLite for preferences for the main goal of saving preferences to the USB partition. I am planning on having a pretty highly customizable app, so it'd be a bit a of a PITA to set it back up after a wipe.
  15. Tibfib's Avatar
    Posts
    345 Posts
    Global Posts
    347 Global Posts
    #15  
    Quote Originally Posted by Laxidasical View Post
    SQLite & Depot data will survive app closing/reopening as well as app updates. I believe cookie data is destroyed when an app closes. If that is the case, you should definitely use one of the former for preferences.
    Cookies stay after you close an app.

Posting Permissions