facebook

Clear text field(s) on application startup: CLOSED

💡
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 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #342242 Reply

    Robert Gardner
    Participant

    Hello Mobi’ers,

    I have a text field that I want to ensure is blank each time the application is started. How do I accomplish this?

    Thanks in advance for your input.

    #342244

    Brandon
    Member

    In your custom_js file you will find an on document loaded function. In there you can place something like this:

    $(‘#m1-yourformname-textField1’).val(”);

    which will set the textfield with no value.

    #342245

    Robert Gardner
    Participant

    Silly question…. where is the file you’re referencing?

    #342246

    support-michael
    Keymaster

    Here is an expanded version of Cincyplanets example. I assume you have an input field widget who’s ID property ends in Field1, e.g., TextField1. The code below is included in the <project>_custom.js file generated by mobione in the <project>_www/ directory.

    /**
     * Called when document is loaded.
     */
    phoneui.documentReadyHandler = function() {  
        document.addEventListener("deviceready", onDeviceReady, false);    
    }
    
    //called when cordova has initialized
    function onDeviceReady() {
        document.addEventListener("resume", onDeviceResume, false);
        clearInput();
    }
    
    //called when the app resumes from background
    function onDeviceResume() {
        clearInput();
    }
    
    //set the inputfield widget's text to empty string
    function clearInput() {
        $('[id$=Field1]').val('');
    }
    #342247

    Brandon
    Member

    @Wayne
    Great sample, I modified it a bit for the mobius blog: http://cincyplanet.com/mobius/

    #342248

    Robert Gardner
    Participant

    Hummm… I attempted to add the code you suggested.. Clearly I must be doing something wrong. It doesn’t clear the text… What am I missing?

    Thank you

    Attachments:
    You must be logged in to view attached files.
    #342249

    Brandon
    Member

    You need these lines as they initiate the clearing on startup:

    * Called when document is loaded.
    */
    phoneui.documentReadyHandler = function() {
    document.addEventListener(“deviceready”, onDeviceReady, false);
    }

    //called when cordova has initialized
    function onDeviceReady() {
    document.addEventListener(“resume”, onDeviceResume, false); //ONLY NEED TO CLEAR ON RESUME
    clearInput();
    }

    #342250

    Robert Gardner
    Participant

    Cut and pasted your input to my custom.js file. Saved the updated file and rebuilt the app. I clearly am overlooking something.. It’s not clearing the text. 🙁

    I’ve included the complete custom.js file for my project for review…(minus the comments at the top)

    Thanks,

    Attachments:
    You must be logged in to view attached files.
    #342251

    Brandon
    Member

    Try pasting this, make sure you dont have any double functions:

    /**
    * Called when document is loaded.
    */
    phoneui.documentReadyHandler = function() {
    document.addEventListener(“deviceready”, onDeviceReady, false);
    }

    //called when cordova has initialized
    function onDeviceReady() {
    document.addEventListener(“resume”, onDeviceResume, false);
    clearInput();
    }

    //called when the app resumes from background
    function onDeviceResume() {
    clearInput();
    }

    //set the inputfield widget’s text to empty string
    function clearInput() {
    $(‘[id$=LegNote]’).val(”);
    }

    #342259

    Robert Gardner
    Participant

    You win all the points… 🙂 That did it… I’ll have to review in detail to see what I did incorrectly the first couple of times…

    Thank you!

    #342279

    Robert Gardner
    Participant

    Bonus round follow up question…..If I want to clear another text field where do I place the additonal code in the custome .js

    This is the last line in the custom.js file. Do I duplicate all this or can I embed the code in the existing function?

    //Clear the LegNote text each time app is resumed
    function clearInput() {
    $(‘[id$=LegNote]’).val(”);
    }

    Also, where can I read up on the phone functions described in the custom.js file…

    Thanks again in advance for your input..

    #342284

    Brandon
    Member

    Glad I could help.

    You can place it in the same function:

    Good Learning resources are:
    http://www.genuitec.com/mobile/learningcenter.php
    http://cincyplanet.com/mobius
    http://cincyplanet.com/mobione/

    and, for more advanced Cordova functions and features:
    http://docs.phonegap.com

    and for basic javascript learning:
    http://www.w3schools.com

    #342289

    Robert Gardner
    Participant

    Thank you again!

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: Clear text field(s) on application startup: CLOSED

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