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

Conditionally prevent delete in a grid

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

    Conditionally prevent delete in a grid

    I have a grid built on a DBF table. I have the grid properties set to allow deletes.

    I want to prevent the delete of the record if a certain logical field is set to true.

    Can this be done?

    I see that the server-side events has a CanDeleteRecord function. I look at the code but it doesn't make any sense to me. I think I'm in the right place but I'm not sure what code needs to be put here.

    It looks like I have to change the line Result.Cancel = .f. to Result.Cancel = .t. and that will stop the delete.


    TIA,

    Ron
    Last edited by Ronald Anusiewicz; 10-04-2015, 09:22 AM.
    Alpha 5 Version 11
    AA Build 2999, Build 4269, Current Build
    DBF's and MySql
    Desktop, Web on the Desktop and WEB

    Ron Anusiewicz

    #2
    Re: Conditionally prevent delete in a grid

    you need to get hold of the field and check it.
    comment out the result.cancel and result .html
    then in that place between the with and end with statements you add
    dim field as something ( that should match what you want to check, like logical)
    field = DataSubmitted.logical field
    if field = .t. then
    Result.cancel = .t.
    Result.HTML = "Error you cannot delete this record, Please undo "
    end if

    I think there is a place actually you can abort the delete. if I find it I will let you know.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    [email protected]
    Skype:[email protected]
    1 914 924 5171

    Comment


      #3
      Re: Conditionally prevent delete in a grid

      Thank you Gandhi

      Works perfectly.

      Actually, I spoke a moment too soon. The DataSubmitted returns character fields so I had to change from a logical to a character.
      Now everything is working fine.

      Code:
      function CanDeleteRecord as v (DataSubmitted as P, Args as p, PageVariables as p, Result as P)
      with PageVariables
      'Result.Cancel = .f.
      'Result.ErrorHTML = ""
      
      'debug(1)
      
      dim vPosted as C
      vPosted = DataSubmitted.Posted
      if vPosted = "True" then
      	Result.Cancel = .t.
      	Result.ErrorHTML = "Sorry, the Record Has Been Posted and Can Not be Deleted"
      end if
      
      end with
      end function
      Last edited by Ronald Anusiewicz; 10-04-2015, 11:09 AM.
      Alpha 5 Version 11
      AA Build 2999, Build 4269, Current Build
      DBF's and MySql
      Desktop, Web on the Desktop and WEB

      Ron Anusiewicz

      Comment


        #4
        Re: Conditionally prevent delete in a grid

        Ron,

        Depending on how your Grid is set up for deleting records, there may be a better way to do this. Do you have a delete icon or button that you're using to delete a row in your grid? If so, then I don't think you need to take a trip to the server in order to run a test for deletion. You're making an ajax callback to the server, sending data to the server, testing that data, and sending back decision results. That's kinda like going to the store carrying a loaf of bread... to get a loaf of bread.

        The grid has a client-side event... canRowDelete. A parameter of this event is rowNumber. Since you're testing data that exists in your grid, then you can test at the client side and not have to make a trip to the server.

        Code:
        var isPosted = {grid.Object}.getValue('G','POSTED',e.rowNumber);
        if(isPosted == 'True'){
        	alert('sorry... can not delete');
        	return false;
        }else{
        	alert('ok to delete');
        	return true;
        }
        We get the value of POSTED, based on e.rowNumber passed into the event.
        We test it and decide what to do. We return true if the record can be deleted, and false if not.
        You may have to confirm what the value of 'isPosted' turns out to be... character, logical.

        Whenever possible, keep these decisions at the client level... don't trouble the server with unnecessary tasks.

        Comment


          #5
          Re: Conditionally prevent delete in a grid

          Thanks David. Sometimes the toughest thing in web design is where to put the code. Also, it's a heck of a lot faster on the client side. Almost instantaneous.

          Comment


            #6
            Re: Conditionally prevent delete in a grid

            David,

            Thank you for your response. I fully understand what you are saying. I'm going through a major learning curve here trying to do WEB apps coming from over 20 years of using Alpha on the desktop.

            Anyways, I can not get the client side to work.

            I have a grid which allows deletes. I have a column with a check box to delete that row. I check the rows I want to delete and then I press the submit button to remove the rows. The server side event code works. The grid is built on a DBF table. The field POSTED is a logical field of true or false.

            I tried your code and different variations and nothing works. Is there a debugger for javascript?
            Alpha 5 Version 11
            AA Build 2999, Build 4269, Current Build
            DBF's and MySql
            Desktop, Web on the Desktop and WEB

            Ron Anusiewicz

            Comment


              #7
              Re: Conditionally prevent delete in a grid

              Yes... that's why I was saying that it depends on how your delete is set up. With a checkbox, you're submitting all the deletes (in a sense) at once via the Submit button. The server code then loops through all your deletes, deleteing where it can, and sending back errors when it can't.

              If you wanted to stay client-side you could use the canGridSubmit event and look at the {grid.Object}._dirtyRows to see which rows are dirty and then determine if the row could be deleted. This gets a bit more involved, however.

              Also remember, that using the checkbox for delete, an ajax callback is made each time you first check that box.

              Javascript has an excellent debugger. There are a number of great references, videos, etc. to the debugger in the Release Notes.

              Comment


                #8
                Re: Conditionally prevent delete in a grid

                i tried many times with canRowDelete event and this does not work, i am not sure that event looks for return false.
                however i have successfully implemented similar code in
                canRowSubmit and as well as canGridSubmit. they both take return false.
                that is what i wanted to show Ron in my first post.
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                  #9
                  Re: Conditionally prevent delete in a grid

                  canRowDelete does work. It is not logical to use this event when the grid is set to use a Delete Checkbox since the Delete Checkbox is tied to the Grid Submit button. If, however, you are using an immediate row delete process, when the Delete record control is set to Icon, then canRowDelete fires... as it should.

                  Comment


                    #10
                    Re: Conditionally prevent delete in a grid

                    probably it does, so far it did not work for me i will test again later on to see. something i must be doing wrong here.
                    thanks for reading

                    gandhi

                    version 11 3381 - 4096
                    mysql backend
                    http://www.alphawebprogramming.blogspot.com
                    [email protected]
                    Skype:[email protected]
                    1 914 924 5171

                    Comment


                      #11
                      Re: Conditionally prevent delete in a grid

                      Thanks Dave, I finally get it. After your explanation to Gandhi, I changed from a checkbox to an icon and now the client side works.
                      Alpha 5 Version 11
                      AA Build 2999, Build 4269, Current Build
                      DBF's and MySql
                      Desktop, Web on the Desktop and WEB

                      Ron Anusiewicz

                      Comment


                        #12
                        Re: Conditionally prevent delete in a grid

                        ditto, thanks.
                        i never tried earlier with icon, so it failed all the time.
                        thanks for reading

                        gandhi

                        version 11 3381 - 4096
                        mysql backend
                        http://www.alphawebprogramming.blogspot.com
                        [email protected]
                        Skype:[email protected]
                        1 914 924 5171

                        Comment

                        Working...
                        X