facebook

Populating fields on page load/app start with saved data

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 15 posts - 16 through 30 (of 38 total)
  • Author
    Posts
  • #347446

    belmont
    Member

    Sorry I haven’t posted earlier, for some reason I didn’t get a notification in my inbox.

    For time being I am using the setItem code on for on change button, and the getItem code to run in the custom.js file for PostPageTransition.

    I am still using a button called SAVE, however, the only function added to it, is to go to screen, basically so that it appears that it is saving the data.

    So I have 3 pages.
    The 3rd page has the user input fields, with the save button. On saving the page transitions to the second page,
    The 2nd page is esentially a copy of the 3rd page, but all the textfields are read only, and automatically populated with the data input from page 3.
    Page 1 has a list of names (which start off with placeholder text & are again automatically populated from page 3).

    Am pretty happy with that for time being, but I will also look into incorporating the last bit of code advise you have both shared.

    _________________________

    Another question, if I update my app, use the same textfield ID’s (to call the information saved to local storage) but on new pages, will update the saved data, or is the data lost on upgrade>

    THank you again sooooo so much

    #347447

    Code_A
    Member

    The data will still be saved in local storage when you update your app.

    Keep in mind, the data is not stored or linked to a specific screen or text field, it is saved under the assigned key you defined when you used .setItem. The data stored under that key can be used anywhere in your app (i.e., any screen, any textfield, etc.) by calling .getItem.

    EDIT: Fixed auto-corrected words!

    #348245

    falloffalot
    Member

    @CincyPlanet wrote:

    Instead of a save button when I want to save the text from a field into localStorage I use the text fields onChange event. This way anytime any text is placed it is ‘automatically’ saved, so it the person closes the app, or it crashes, the data is still saved.

    I realize this is an old post, but this way sounds logic.
    What code would I need to enter into the “OnChange” JS?

    Cheers J

    #348246

    Brandon
    Member

    The code below can be placed in either onChange event of the text box or the onClick event of the button and the result should be the same.
    Code:
    localStorage.setItem(‘datafield’,$(‘#m1-locstorage-datafield’).val());

    #348248

    falloffalot
    Member

    wow that was quick, thank you.
    I input that code into the
    “OnChange” > Run JavaScript > Code
    Then Publish and test on my iPad2, I input text in the Text Field and exit the app.
    I re-open the app and the text Field is still blank.
    What am I doing wrong?

    #348249

    Brandon
    Member

    In your custom.js file you have to call the text back into the textbox in the startup function (document loaded) like

    $(‘#m1-locstorage-datafield’).val(localStorage.getItem(‘datafield’));

    #348254

    falloffalot
    Member

    Having a bit of trouble with file locations, as this file was only in the User>AppData>Temp! (is this right?)
    I am assuming its the highlighted one?

    This is all the script in that file, where would I put: localStorage.setItem(‘datafield’,$(‘#m1-locstorage-datafield’).val());

    /**
    * Notification that the UI is about to transition to a new screen.
    * Perform custom prescreen-transition logic here.
    * @param {String} currentScreenId
    * @param {String} targetScreenId
    * @returns {boolean} true to continue transtion; false to halt transition
    */
    phoneui.prePageTransition = function(currentScreenId, targetScreenId) {
    // add custom pre-transition code here
    // return false to terminate transition
    return true;
    }

    /**
    * Notification that the UI has transitioned to a new screen.
    *
    * @param {String} newScreenId
    */
    phoneui.postPageTransition = function(newScreenId) {

    }

    /**
    * Notification that the page’s HTML/CSS/JS is about to be loaded.
    * Perform custom logic here, f.e. you can cancel request to the server.
    * @param {String} targetScreenId
    * @returns {boolean} true to continue loading; false to halt loading
    */
    phoneui.prePageLoad = function(targetScreenId) {
    // add custom pre-load code here
    // return false to terminate page loading, this cancels transition to page as well

    return true;
    }

    /**
    * Notification that device orientation has changed.
    *
    * @param {String} newOrientation
    */
    phoneui.postOrientationChange = function(newOrientation) {

    }

    /**
    * Called when document is loaded.
    */
    phoneui.documentReadyHandler = function() {
    }

    #348257

    Brandon
    Member

    It should be that file, but not in the temp folder. It should be in the project folder (where you saved the mobi files) in the www folder.

    #348261

    falloffalot
    Member

    Never seen any www file or folder when I save any project!

    When I try to change the destination folder I just get open > open > open > open ….etc and no option to save!

    #348286

    Brandon
    Member

    The files in the temp folder can be erased at any time, so using them for your project is probably a disaster waiting to happen.
    The first thing you should do is copy your custom js file into a safe folder (my documents or desktop).
    Then use this as a guide to generate your application files and copy you saved custom js file into this www folder.

    http://www.genuitec.com/support-genuitec/viewtopic.php?p=23844#p23844

    #348290

    falloffalot
    Member

    Ahhhhh….right got it!
    There it is www folder yay
    Thanks for help…again 😉

    #348292

    Brandon
    Member

    No problem, glad you got it figured out.

    #348296

    falloffalot
    Member

    Great help as always, my only problem now is:
    I have a simple text box with OnChange – Run Javascript –

    And in the Custom JS folder within www I have:

    I publish and open on my iPad2 > Add to Home Screen > open App > type in field > close App!
    Open App again and the text box is still blank?
    This is driving me crackers guys…aaaahhhhhhhhhhhh

    #348297

    Brandon
    Member

    I cant see any real problems except maybe keep consistent with your quotation marks, use single ones in the document load also, see if that makes a difference (not sure if it will or not).

    You can also use the chrome tools to check the localstorage data or
    In your document load you can aslo use:
    alert(localStorage.getItem(‘datafield’));

    to make sure the data is getting written

    #348298

    falloffalot
    Member

    Nope…still no go i’m afraid!
    I must be be doing something really simple wrong, but I cant figure it out!
    Can I just ask, all functions do work when published to a device for testing?

Viewing 15 posts - 16 through 30 (of 38 total)
Reply To: Populating fields on page load/app start with saved data

You must be logged in to post in the forum log in