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

A custom control that can access the data on a form using javascript.

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

    A custom control that can access the data on a form using javascript.

    This may all be easy in ver 10 but for those of us still using ver 9 the following might be worthwhile. It also gave me some insight into custom controls.
    I have found it useful to provide users more than one way to submit a grid form which might send them to various other pages depending on which submit button they use. There is a thread "Two submit buttons on a grid´┐Ż" which does just that. But here I wanted to redirect to the same page but have different actions before leaving the page the user is on. I wanted to use a custom control as a second submit button but still have access to the validations events. All the documentation that I have been able to find, describes how to define a custom control's appearance but not how to actually have the custom control do anything. In fact I have seen statements that a custom control is only for display. I have used javascript in a custom control definition which can access and change the data on the form.

    I have a field named "sendit" on my grid. It happens to be a logical and it happens to be hidden and it happens to be in the detail section of the grid but none of these are required. The same grid contains a variable named "signit" as type C but any type would do as it never actually gets any data. Signit is assigned to a custom control defined as follows (all on one line).

    Signit_render = <<%html%
    <input type="button" value="Save and send to the office." onClick="document.forms['transcripts'].elements['V.R1.SENDIT'].value='T';
    document.forms['transcripts'].transcripts_DetailView_Save.click()"
    style="BORDER-BOTTOM: 1px solid; BORDER-LEFT: 1px solid;
    BACKGROUND-COLOR: #f9ead6; BORDER-RIGHT: 1px solid;
    BORDER-: 1px solid">
    %html%

    When the user clicks the custom control named signit (labeled "Save and send to the office."), two things happen in sequence. First the value of the hidden field "sendit" is set to true and then the code emulates a click of the form submit button (labled "Save"). The emulation is complete and the forms validation events do occur.

    The trick is knowing the names of the two objects, the field sendit and the actual submit button. That you can get by examining the source code of the final a5w page in a browser. In this case I found two statements describing the two objects. They were:

    <input type="hidden" id="V.R1. SENDIT " name="V.R1. SENDIT " value="False" />

    and

    <input class="npapnatucketButton" type="submit" value="Save" name="transcripts_DetailView_Save">

    So those are the names I used in the inline javascript.

    This simple technique has many possibilities. One click of this button could be used to set the values of multiple fields at the same time. Even better is the use of the custom control to set the value of a variable and then have a validate event read the value of that variable and carry out other operations accordingly since you can include almost anything in the validate events using xbasic.

    It is also possible to have the javascript in the custom control call a javascript function defined elsewhere on the a5w page but the use of this inline javascript is appealing.

    I have benefited greatly from what I have learned from others on this forum and I hope someone can make use of this.
    Thanks,
    Irwin

    #2
    Re: A custom control that can access the data on a form using javascript.

    Irwin,

    I have used the code you have provided above and it works flawlessly. Thanks for sharing.

    I have two questions where the above code is used.

    1. Where you mention you can set the value of a variable from the custom control. How is that bit incorporated within your code? I need to take a value from the form and put it into a session variable.
    2. How can I set a field value on the form when I press the above custom control button?

    Thanks,

    Denis
    Last edited by den1s; 03-23-2013, 01:41 PM.

    Comment


      #3
      Re: A custom control that can access the data on a form using javascript.

      Irwin,

      I have solved question 2. Now just need to know how I can set a session.variable from a field value on my form, when i press the custom button.

      Thanks,

      Denis

      Comment


        #4
        Re: A custom control that can access the data on a form using javascript.

        Hi Denis
        I am glad you found this useful. Since the custom control includes code that emulates a click of the form submit button, you have full access to the validate and after validate events. There you can use xbasic to set the values of session variables. The syntax is different for grid and dialog components and for the validate and after validate events but some examples from my code are:

        BeforeValidate in grid component
        function BeforeValidateExistingRecords as v (DataSubmitted as P, Args as p, PageVariables as p)
        with PageVariables
        session.vc1=Args.DataSubmitted.R1.vc1
        end with
        end function

        after validate in dialog component
        session.syllcode=alltrim(CurrentForm.Controls.coursecode)

        If you need more appropriate examples let me know with more details. Please note that I often use this with grid components where only one record is displayed and there is only one custom control. If you want to use a grid with several records displayed, with a custom control on each line and a different action for each, that can be done too. Its more complicated but I will be happy to get into that if you want. I am sure you have also noted that in order to use the validate or after validate code, the form must be submitted. While you can set the value of a field with a custom control without a form submission the only way this method can read a field value and set a session variable is with a submission. Maybe you can use the validate event to set the session variable and then set CurrentForm.Has_Error=.t. to cancel the submission but I have not tried that (just thought of it).
        Good luck and good coding.
        Irwin

        Comment


          #5
          Re: A custom control that can access the data on a form using javascript.

          Irwin,

          Thank you for your response.

          I also have a grid with a single record being displayed. If I press the custom control button, how can I set a value in that custom control so that the validate event knows i pressed the custom control button?

          for example,

          if <custom control button value> then
          session.vc1=Args.DataSubmitted.R1.vc1
          else
          session.vc1="other value"
          end if

          Thanks,

          Denis

          Comment


            #6
            Re: A custom control that can access the data on a form using javascript.

            Hi Irwin,

            Moving this on a bit. I have two scripts that both work individially within a custom control.

            C_activity_icon_render = "<input type=button value=\"Confirm Decision\" onClick=\"myRef = window.open('confirm.a5w?session.bd={brief_description}','mywin','left=200,top=200,width=870,height=450,toolbar=0,scrollbars=0,resizable=0,status=0,location=0');myRef.focus()\">"

            C_activity_icon_render = <<%html%
            <input type="button" value="Confirm and Submit" onClick="document.forms['grd_show_decisi'].elements['V.R1.STATUS3'].value='Confirmed';
            document.forms['grd_show_decisi'].grd_show_decisi_Button_Submit.click()">
            %html%

            My ultimate goal is to have both scripts work together when i select the custom control button. i.e.

            1. Set the value of the STATUS3 field in the form
            2. Set the session.bd variable to the value from the brief description field
            3. Submit the form. (Within the validate event i will place an if/else statement to look for the session.var)

            Im not sure how they can be amalgamated together?

            Thanks,

            Denis
            Last edited by den1s; 03-25-2013, 04:51 PM.

            Comment


              #7
              Re: A custom control that can access the data on a form using javascript.

              Hi Denis
              I did this before I read your latest post. I am attaching a zip of a database which does what I think you wanted. It uses a custom control and the validate event to set a session variable to the value in a control on the form. The custom control sets the value of a hidden field to "yes" and then emulates the click of the submit button which then invokes the validate event which sets the session variable if the value in the hidden field is "yes". If you press the submit button directly then the session variable is not changed. If this is not what you want, let me know. I will now study your latest post.
              Regards,
              Irwin
              Attached Files

              Comment


                #8
                Re: A custom control that can access the data on a form using javascript.

                Irwin,

                Thank you so much for your time with this.

                I will take a look at the code and let you know how i get on.

                Denis

                Comment


                  #9
                  Re: A custom control that can access the data on a form using javascript.

                  Denis
                  First, the database I sent you does work fine. But I noticed that in grid1, the field hidden1 is not marked as updateable. It does work that way but it also works if you do mark it as updateable in the field properties. The advantage to that is only that the insert function in the edit screen for the validate event knows about the field and you can select if from the list of datasubmitted fields. Otherwise you have to type in the field name yourself. It's easier if its updatable.
                  It seems to me that if you are trying to get the custom control to do more than one thing or something complicated, you would be better off putting some of the code in the validate or after validate event. In the events you can use xbasic and do almost anything while in the custom control you can really only set and read field values and emulate submit clicks.
                  Irwin

                  Comment


                    #10
                    Re: A custom control that can access the data on a form using javascript.

                    Irwin,

                    This is looking very good. Thank you.

                    I have one piece of the jigsaw left to complete my project.

                    Here is what I am trying to achieve;

                    1. I open the main page grd_list_countries.a5w, that provide a list of records by country
                    2. Click 'View' to view the details of a country.
                    3. You will see a checkbox field called 'Plants' that have some items checked.
                    4. If you wish to add more plants, you can either select any additional unchecked boxes or select the 'Plants List' button which also holds descriptions.
                    5. Select the 'Plants List' button to view the list of available plants with descriptions (grd_open_plants). You will notice that the plants checked boxes are equal to the checked boxes from the currently viewed record. (your code helped me with that bit.) This populates a temp table (tbl_plants_tmp).
                    6. I now need to select or unselect plants from the grd_open_plants page and upon selecting submit, this needs to update the current record.

                    I cannot seem to work out how to do No.6 from my list.

                    I think I need to create some form of array to capture the checked values and then convert that array to a comma delimited field to be updated in my table.

                    What do you think.

                    Denis
                    Attached Files

                    Comment


                      #11
                      Re: A custom control that can access the data on a form using javascript.

                      Hi Denis
                      It seems to me that once you have updated tbl_plants_tmp using grd_open_plants.a5wcmp, you can include code in the grid "after update" event to read the tmp table and update the current record tbl_plants. I find that event really useful for that kind of work. I will have to study your sample some more because I have not used views and I have not figured out how it works and what are the side effect and benefits.
                      Best
                      Irwin

                      Comment


                        #12
                        Re: A custom control that can access the data on a form using javascript.

                        Irwin,

                        The custom control triggers most of it.

                        Any help with this will be greatly appreciated.

                        Thanks,

                        Denis

                        Comment


                          #13
                          Re: A custom control that can access the data on a form using javascript.

                          Hi Denis
                          I think you are trying to do more in the javascript in the custom control then I know how to do. I only use the custom control to set a hidden field so the code in the validate or after validate events is triggered to do the updates etc as shown in the sample I sent you earlier. It's much easier to do almost anything using xbasic but that has to be in one of post submit events.
                          Best wishes,
                          Irwin

                          Comment


                            #14
                            Re: A custom control that can access the data on a form using javascript.

                            Thanks Irwin.

                            You have been a great help with my pursuits to add some new functionality to my db.

                            Kind regards,

                            Denis

                            Comment

                            Working...
                            X