Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Javascript Variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Javascript Variables

    I have set a few variables in the client-side events onInitalizeComplete and onRenderComplete such as

    var s1 = "something"
    var s2 = "something else"

    When I try and use those variables in some additional code in the UX....such as a button, those variables do not exist.

    Question is why does this happen and where is the best place to initialize variables (client-side) to be used throughout a UX compoent

    Thanks

    #2
    Re: Javascript Variables

    When using "var" you are setting those variables local to those events... they are only available inside those events.

    If you'd like a variable to be available through the UX then you could assign it to the {dialog.Object} namespace variable. This keeps it local(ish) and doesn't pollute the DOM. You could set your variable without the word "var" which would assign it to the DOM and therefore make it global, but that's called polluting the DOM and if considered bad form.

    When using {dialog.Object}, I use a naming convention of 2 underbars and then my var name.

    Code:
    {dialog.Object}.__s1 = "something";
    {dialog.Object}.__s2 = "something else";
    Where ever you want to use that variable...

    Code:
    var myNewVar = {dialog.Object}.__s1;
    If you have a lot of variable and would like to be tidy about it... you could establish a {dialog.Object} namespace variable object... and then assign properties of that object to your variable values.

    Code:
    {dialog.Object}.__appVars = {};
    {dialog.Object}.__appVars.s1 = "something";
    {dialog.Object}.__appVars.s2 = "something else";
    Now you know that all your variables are inside {dialog.Object}.__appVars.

    As well, you could use State variables.
    Last edited by Davidk; 05-29-2018, 04:59 PM.

    Comment


      #3
      Re: Javascript Variables

      Thanks David

      Comment


        #4
        Re: Javascript Variables

        Tom, the AlphaAnywhere "state" variables that David has mentioned in at least two posts now to you, can be a nice way to go.

        But take caution: They do not always exist when they should - Alpha has problems re-establish the state variables for you. Besides your code that initializes state variables, any other subsequent code that tries to use your state variables should check for their existence and do nothing if they do not exist yet. When I have seen this happen on the client-side, alpha ends up calling your code a second time with the state variables properly initialized.

        The nice thing about state variables is that they are typically available to both your Xbasic code and your JavaScript code.

        Look for server-side state variable documentation in following pages:
        Grid - server side
        UX - server side

        For client-side info, lookup up
        .setStateInfo
        .getStateInfo

        If you only need the variables on the client-side then I would go with attaching your variables to the UX or Grid component like David mentioned. I usually do this in *RenderComplete or *InitializeComplete. If you allow AA to use a "cached" grid or UX, there might be another client-side event you will have to use, like: "onSynchronizeDialog" for a UX (I don't know the equivalent for a Grid).

        Comment


          #5
          Re: Javascript Variables

          Setting variables, even with the word "var", in the "global" Javascript functions section makes them global also, right? (I am of course not taking about setting them within a custom function that one may have added there).

          Comment


            #6
            Re: Javascript Variables

            Jeff,
            Not necessarily. variables declared like "var somevar = 'something';" outside of any function definitions, but inside the "global" JavaScript functions section of a component might not be readily accessible to other components. The variable ('somevar' in this case) will become a property of the 'window' object. The problem is the 'window' object is similar (IMHO) to how the 'this' object works, but on a grander scale -- the 'window' object represents a current context for running code. If you are running in an i-frame the 'window' object has a different context then when not running in an i-frame.

            For example: Take the "home" page tab in a TabbedUI: make a UX that initializes a variable in its "global" section, make an a5w page for the UX and place the a5w page into the "home" page properties of the tabbed UI. AA will run this a5w page in an i-frame. Put a button in the tabbedUI to display an alert with the variable initialized in the UX.

            If you declared your variable like, "var myvar = 'something';" then you will not be able to see it from tabbedUI button (unless you figure-out the window object (i-frame) that the "home" page is running in look for the 'myvar' property in it.

            If you instead initialize the variable like this:
            window.parent.myvar = 'break out of the i-frame';

            then you could access the variable from the tabbedUI. You can use either of these in the tabbedUI button to access it:
            alert(window.parent.myvar);
            alert(window.myvar);
            alert(myvar);

            Keep in mind that if you navigate to a different a5w page that the browser is going to give you a fresh 'window' object and you will not be able to see your variable anymore.

            Also, if you run something in an i-frame (like opening an a5w page in a tab) from the tabbedUI then code in that i-frame can get to your variable in the same way the homepage tab did: window.parent.myvar.

            Note that the top most 'window' object will always have its '.parent' property point to itself. That is why alert(window.parent.myvar) would work in my example above with a button on the TabbedUI with the alert statement.

            Comment


              #7
              Re: Javascript Variables

              Right. I was being very narrow focused and addressing what I understood to be a question about using variables throughout "a" (single) UX component. My understanding of what that means is that it is a single page application.
              I assumed that if using one of the {dialog.object} approaches presented above would work for his context that my suggestion could also. That being said, I am in no way trying to say that declaring variables as I suggested is a good idea. I know that many consider allowing variables to be available (for reading and updating) to large portions of an application to be very bad practice. I should not have suggested it without the warnings.
              A better suggestion might have been to stick the values in LocalStorage.
              Another option perhaps is using the Custom Settings in Properties of the UX. However, I have never tried using it and only imagine that they would not fit the case of a multi-page a5w website either.

              Related topic:
              I am wondering about the pros and cons of using, in that global Javascript functions section of configuring a UX, "var bar = function() {....}" versus "function bar() {....}"
              Would "var bar = function() {....}" be as bad as declaring "var somevar = 'something'"? Should this section only be used for Function Declarations and not Function Expressions? I've used both in configuring a UX without really understanding the difference and I do not believe that I've seen problems with using one rather than the other.

              Comment

              Working...
              X