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

Editing a field in a list control when a single or multiple rows are selected

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

    Editing a field in a list control when a single or multiple rows are selected

    (Using an older version 3670)
    My original thought was to add a logical checkbox to the row in a list control and save the values to a sql table. I searched the forum and found a few posts where others were trying to do similar, but more trickier stuff.
    I viewed David Ks video where he updates a table when a checkbox is selected in a row. Very Cool! However this seemed complicated and I couldn't modify it.

    I also viewed the youtube https://www.youtube.com/watch?v=yhcXka5dM2s where a checked image is used. This is exactly what I want, but only
    gets me half way there. I couldn't find, or maybe I am not looking in the right place on how to capture the checked row and link it's alternating value (T or F) to a table field or fields when multiple rows are selected, and then submit it to update the records in a database, in my case mysql.

    Think of the simple example of deleting your voicemails in IOS you check the ones you want deleted and click a master button to delete them. With all the impressive wonders of Alpha's List Control this very basic example isn't Anywhere to be found.
    Help!
    Bob

    #2
    Re: Editing a field in a list control when a single or multiple rows are selected

    I created a video which I hope helps:

    https://www.screencast.com/t/IhZLJztulOrI

    Here is the javascript on the button

    var mySelection = getSelectedRows();

    {dialog.Object}.ajaxCallback('','','updateSQL','','_customersToUpdate=' + mySelection);
    Here is the Javascript function

    function getSelectedRows(){
    var lObj = {Dialog.object}.getControl('list1');
    var len = lObj.selectionData.length;
    debugger;
    var arr = [];
    for (i=0;i<len;i++){
    arr[i] = lObj.selectionData[i].CustomerID
    }
    return JSON.stringify(arr);
    }
    Here is the Xbasic function

    function updateSQL as c (e as p)
    debug(1)

    DIM cn AS sql::Connection
    DIM args AS sql::Arguments
    DIM sqlUpdate AS c =""
    DIM flag1 as l
    DIM flag2 as l

    flag1 = cn.Open("::name::nw")

    IF flag1 = .f. THEN
    updateSQL = "alert('SQL connection failed');"
    end
    END IF

    args.Set("whatCustomers",e._customersToUpdate)
    sqlUpdate = "UPDATE myTable SET thisField = thatValue WHERE CustomerID in :whatCustomers"
    flag2 = cn.Execute(sqlUpdate,args)

    IF flag2 = .f. THEN
    updateSQL = "alert('Records were not updated');"
    end
    ELSE
    updateSQL = "alert('Records were updated successfully');"
    end
    END IF

    end function


    Jay
    Jay Talbott
    Lexington, KY

    Comment


      #3
      Re: Editing a field in a list control when a single or multiple rows are selected

      Very nice Jay !
      Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

      Comment


        #4
        Re: Editing a field in a list control when a single or multiple rows are selected

        You could use the List Control for updating your table. Turn on Detail View for the List, but you do not need to add any Detail View controls. You only need the List Detail View Sync button.

        The List Layout checkbox examples include an onclick event for the checkbox. This Javascript function, for the onclick event, changes the value of the displayed checkbox... and updates the ChkTest data in the List control.
        Once the List data is updated using .updateTableRow()... then you just need to use the Detail View Sync button to update your table.

        Code:
        function clickCheckbox(row){
        
        	var currState = $('myCheckBox'+row).checked;
        	var listObj = {dialog.Object}.getControl('LISTCUST');
        	
        	{dialog.Object}.__checkRow = row;
        	
        	if (currState == true){
        		setTimeout("$('myCheckBox'+{dialog.Object}.__checkRow).checked=true;",150);
        		var data = {};
        		data.ChkTest = 'T';
        		listObj.updateTableRow(row,data);
        	}else{
        		setTimeout("$('myCheckBox'+{dialog.Object}.__checkRow).checked=false;",150);
        		var data = {};
        		data.ChkTest = 'F';
        		listObj.updateTableRow(row,data);
        	}
        	
        }
        The only area to verify is how the data is from ChkTest is being interpreted by Alpha. I've seen it as "True" and "False"... and "T" and "F". It may be release dependent... not sure. So you just need to check it.
        Last edited by Davidk; 10-14-2018, 03:32 PM.

        Comment


          #5
          Re: Editing a field in a list control when a single or multiple rows are selected

          Thanks guys very useful!

          Comment


            #6
            Re: Editing a field in a list control when a single or multiple rows are selected

            2018-10-15.png
            Tried Jay's example, however my debugger isn't logging anything at the bottom. Not real experienced with the debugger is there a setting I am missing?

            It seems e._customers to update is returning null, so guess my problem is somewhere in the javascript function or the button javascript. Guess that is why I m not logging anything in the console.
            Last edited by bob9145; 10-15-2018, 09:24 AM.

            Comment


              #7
              Re: Editing a field in a list control when a single or multiple rows are selected

              Bob,
              (The Xbasic debugger is used for Xbasic and the Chrome debugger is used for Javascript. That statement is just to be sure we are on the same page.)

              If you want a value to appear in the Xbasic watch window, as the lower portion is called, you need to put that value in the watch window.

              Some values can be double clicked in the window above to be assigned in the space below, or you can type the value you want to see in the area under the word "Expression". You will need to hit the [ENTER] key when you are finished typing the expression, and the value should appear as long as you have passed that part in the script above (by clicking on Step). Prior to the value being assigned in the script above, the watch window will say something like value not assigned.

              Let us know if you need more help.

              Jay
              Jay Talbott
              Lexington, KY

              Comment


                #8
                Re: Editing a field in a list control when a single or multiple rows are selected

                Thanks Jay! Got the debug watch Window working. Don't quite understand where e._customersToUpdate comes from? How and where is this variable defined? In my case I don't seem to be populating it.

                Comment


                  #9
                  Re: Editing a field in a list control when a single or multiple rows are selected

                  Bob,
                  The e._customersToUpdate comes from the javascript function (first bubble in my original post), which gets its value from the js function.
                  I think I need to amend my XBasic.
                  Try this if the above does not work:

                  function updateSQL as c (e as p)
                  'debug(1)

                  DIM cn AS sql::Connection
                  DIM args AS sql::Arguments
                  DIM sqlUpdate AS c =""
                  DIM flag1 as l
                  DIM flag2 as l

                  flag1 = cn.Open("::name::nw")

                  IF flag1 = .f. THEN
                  updateSQL = "alert('SQL connection failed');"
                  end
                  END IF

                  e._customersToUpdate = strtran(e._customersToUpdate,"[","(")
                  e._customersToUpdate = strtran(e._customersToUpdate,"]",")")

                  args.Set("whatCustomers",e._customersToUpdate)
                  sqlUpdate = "UPDATE myTable SET thisField = thatValue WHERE CustomerID in :whatCustomers"
                  sqlUpdate = strtran(sqlUpdate,"[","(")
                  sqlUpdate = strtran(sqlUpdate,"]",")")
                  sqlUpdate = strtran(sqlUpdate,""(","(")
                  sqlUpdate = strtran(sqlUpdate,")"",")")

                  flag2 = cn.Execute(sqlUpdate,args)

                  IF flag2 = .f. THEN
                  updateSQL = "alert('Records were not updated');"
                  end
                  ELSE
                  updateSQL = "alert('Records were updated successfully');"
                  end
                  END IF

                  end function
                  Jay Talbott
                  Lexington, KY

                  Comment


                    #10
                    Re: Editing a field in a list control when a single or multiple rows are selected

                    Changed the names of the list, table, _variable, and fields to fit my list and table. The selected rows are being counted but the value of the Pay_Id field is not coming through getting null values. Also maybe because the arg is empty the arg name is being added to the statement, :whatCustomers My list is set to the payment table in a mysql database.

                    Oops wrong pic this is the right one

                    2018-10-15 (2).png
                    Attached Files
                    Last edited by bob9145; 10-15-2018, 07:18 PM.

                    Comment


                      #11
                      Re: Editing a field in a list control when a single or multiple rows are selected

                      Bob,
                      Please post a copy of the button script and the js function, as well as the Xbasic script. That'll be the easiest way to get this up and running.
                      Jay
                      Jay Talbott
                      Lexington, KY

                      Comment


                        #12
                        Re: Editing a field in a list control when a single or multiple rows are selected

                        Button Dialog Method
                        var mySelection = getSelectedRows();

                        {dialog.Object}.ajaxCallback('','','updateSQL','','_paymentToUpdate=' + mySelection);
                        Javascript Function
                        function getSelectedRows(){
                        var lObj = {Dialog.object}.getControl('pay');
                        var len = lObj.selectionData.length;
                        debugger;
                        var arr = [];
                        for (i=0;i<len;i++){
                        arr[i] = lObj.selectionData[i].Pay_Id
                        }
                        return JSON.stringify(arr);
                        }
                        xbasic Function
                        DIM cn AS sql::Connection
                        DIM args AS sql::Arguments
                        DIM sqlUpdate AS c =""
                        DIM flag1 as l
                        DIM flag2 as l

                        flag1 = cn.Open("::Name::rmqv12")

                        IF flag1 = .f. THEN
                        updateSQL = "alert('SQL connection failed');"
                        end
                        END IF

                        args.set("whatCustomers",e._paymentToUpdate)
                        sqlUpdate = "UPDATE payment SET pay = F WHERE Pay_Id in :whatCustomers"

                        flag2 = cn.Execute(sqlUpdate,args)

                        IF flag2 = .f. THEN
                        updateSQL = "alert('Records were not updated');"

                        end
                        ELSE
                        updateSQL = "alert('Records were updated successfully');"
                        end
                        END IF

                        end function
                        My list is pay, table is payment, primary key is pay_Id, and I changed the variable to _paymentToupdate
                        The list is based on a mysql table and a simple field query, primary key Pay_Id
                        Thanks!

                        Comment


                          #13
                          Re: Editing a field in a list control when a single or multiple rows are selected

                          Tried the alternate xbasics but Still getting the null value in the variable. Seems like it's not making it into the xbasics script. It's counting the rows but it's not populating the value. If you get your component working
                          post it and I can compare everything. Thanks!
                          Last edited by bob9145; 10-15-2018, 11:28 PM.

                          Comment


                            #14
                            Re: Editing a field in a list control when a single or multiple rows are selected

                            Since Javascript is case sensitive, I am wondering if the list column agrees with this line right here:
                            rr[i] = lObj.selectionData[i].Pay_Id

                            Is Pay_Id cased exactly like that?

                            By the way, you may need to change the Xbasic script to agree with my amended script to get the SQL update statement to work in mySQL

                            Jay
                            Jay Talbott
                            Lexington, KY

                            Comment


                              #15
                              Re: Editing a field in a list control when a single or multiple rows are selected

                              Think the problem is in the Javascript function it's doesn't seem to populate the variable.
                              function getSelectedRows(){
                              var lObj = {Dialog.object}.getControl('pay');
                              var len = lObj.selectionData.length;
                              debugger;
                              var arr = [];
                              for (i=0;i<len;i++){
                              arr[i] = lObj.selectionData[i].Pay_Id
                              }
                              return JSON.stringify(arr);
                              }
                              I stripped the xbasic down and just tried to populate the variable e.control.paytest = e._paymenttoupdate the control shows {null,null,null]

                              Comment

                              Working...
                              X