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

Validation Of One Field 'OR' Another Field

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

    Validation Of One Field 'OR' Another Field

    I have validation on a dropdown char field where the user must make a selection.

    Now I need a case where I want to apply validation to 2 dropdown fields where the user must either select one field OR the other but not necessarily both.
    Has anyone done this perhaps?

    Thanks,
    Stephen
    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

    #2
    Re: Validation Of One Field 'OR' Another Field

    I haven't tried it, but could you make a field with a calculated value that is the concatenation of the two fields that need to be validated, and then require the calculated field to have a value?
    Jay
    Jay Talbott
    Lexington, KY

    Comment


      #3
      Re: Validation Of One Field 'OR' Another Field

      assuming you are using a dialog, do you want immediate validation?
      this can be tested in the dialogValidate event, I am sure.

      edit: actually you can do it in the field immediate validate definition area itself.
      go to validation xbasic in the first field uncomment the if end if statement
      and add the second field also in evaluation as below, replacing your field names. do the same in the second dropdown. except change the validate_field1 to field2
      Code:
      if e.data.field1 = "" .and. e.data.field2 = "" then
         validate_field1.hasError = .t.
         validate_field1.errorText = "field1 cannot be blank if field2 is also blank."
      end if
      Last edited by GGandhi; 04-17-2015, 08:41 AM.
      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


        #4
        Re: Validation Of One Field 'OR' Another Field

        Thanks for the good suggestions guys. Your method seems to work Ghandi. The only odd thing is that only the first field gets highlighted in red.
        I added the same code to the second field's xbasic validation and that seems to work highlighting both fields if they are empty.

        So this code in the first field only:

        Code:
        function validate_field1 as p (e as p)
        
        if e.data.field1 = "" .and. e.data.field2 = "" then
           validate_field1.hasError = .t. 
           validate_field1.errorText = "At least one Physics or Engineering personel is required."
        end if	
        
        end function
        Will only highlight field1 in red when validation errors like this:

        Multi-Validation.jpg

        I also tried this but it doesn't seem to work.
        Code:
        function validate_field1 as p (e as p)
        
        if e.data.field1 = "" .and. e.data.field2 = "" then
           validate_field1.hasError = .t. 
           validate_field2.hasError = .t.
           validate_field1.errorText = "At least one Physics or Engineering personel is required."
        end if	
        
        end function
        Adding the same code in the second field like this seems to work:

        Code:
        function validate_field2 as p (e as p)
        
        if e.data.field2 = "" .and. e.data.field1 = "" then
           validate_field2.hasError = .t. 
           validate_field2.errorText = "At least one Physics or Engineering personel is required."
        end if	
        
        end function
        Highlights both fields in red:

        Multi-Validation2.jpg

        I'm not sure if this is the best way to do it but it seems to be working as expected and not causing any strange behaviour.

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

        Comment


          #5
          Re: Validation Of One Field 'OR' Another Field

          do the same in the second dropdown. except change the validate_field1 to field2
          yes you need to do for both fields.
          glad to hear it is working out for you, good.
          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


            #6
            Re: Validation Of One Field 'OR' Another Field

            Originally posted by GGandhi View Post
            yes you need to do for both fields.
            glad to hear it is working out for you, good.
            Yes, you did say that didn't you. Sometimes I don't listen so well

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

            Comment


              #7
              Re: Validation Of One Field 'OR' Another Field

              I feel that this isn't the best way to utilize the tools we've been given... and it kinda breaks the client-side / server-side philosophy.

              This is like saying... I want to bake a cake... but I keep my recipe book at the grocery store. I think I may have what I need... but let me go check. So you grab an egg and head out the door passing a friend along the way. Your friend asks where you're going and you ignore them.

              You get to the grocery store and check your recipe. It says you need at least one egg. You check your hands... and yup... you have an egg. All happy you head back home. If you continue this scenario... then when you get home you'll ask yourself if you need flour... and by the end of the day you're a very tired baker... and... you're friend is kinda ticked of for being ignored.

              What you could have done is let your friend know where you're going. Your friend just happens to be a world renowned expert on cake baking. You'd say... I'm going to the grocery store to see what I need to bake a cake... I think I need at least one egg. Your friend says... yup... you need at least one egg... no need to walk all the way to the store. And... by the way... I can help with the rest of the cake. Everybody's happy.

              So... why not let the client side check to see if you've got eggs. And... if not... let you know about it.

              Plus... going server-side... if you do have an error... additions are being made the the DOM. So... there's a lot going on... but, in this case, it's not needed.

              Here's a simple UX and video to illustrate the concept. The onChange events of the dropdowns need a bit more work so that each dropdown will test for both dropdowns... but this will get you started.

              http://www.youtube.com/watch?v=QiJg8omzuS0
              Attached Files

              Comment


                #8
                Re: Validation Of One Field 'OR' Another Field

                David,

                Wow, thank you so much for that excellent video and explanation. You know, there was something nagging me about the way I was implementing this, but it seemed to work and I didn't know any other way to accomplish the task. This is a great technique, I was unaware of setting class properties like that. It totally makes sense not to be making calls back to the server if you don't have to. I've implemented this method and it works great!

                I had to change the css style name from iOS7 to GrBlue to match what I am using in my UX component. With iOS7 the validation worked, preventing a submit, but it didn't turn the field red unless I used GrBlue which is the style I'm using in my UX. I have it set in the onclick event of my submit button, so it ended up like this:

                Code:
                var dd1Ele = {dialog.object}.getPointer('Field1');
                var dd2Ele = {dialog.object}.getPointer('Field2');
                
                var dd1 = $gvs(dd1Ele);
                var dd2 = $gvs(dd2Ele);
                
                if ( (dd1 == "") && (dd2 == "") ) {
                
                   $acn(dd1Ele,'GrBlueEditError');
                   $acn(dd2Ele,'GrBlueEditError');
                   $sa(dd1Ele,'title','At least one Field1 or Field2 selection is required.'); 
                   $sa(dd2Ele,'title','At least one Field1 or Field2 selection is required.');
                
                } else {
                
                   $rcn(dd1Ele,'GrBlueEditError');
                   $rcn(dd2Ele,'GrBlueEditError');
                   $sa(dd1Ele,'title','');
                   $sa(dd2Ele,'title','');
                   
                   {dialog.object}.submit();
                   
                   //Disable the 'SUBMIT' button.
                   this.disabled=true;
                   //Disable the 'UNDO' button.
                   {dialog.object}.setDisabled('BUTTON_RESET');
                }
                Thank very much for taking the time to pass along this FANTASTIC method.

                btw, I'm not a very good baker

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

                Comment


                  #9
                  Re: Validation Of One Field 'OR' Another Field

                  Good to hear... glad it worked out. This stuff gets really important when you start to look at mobile. You want to do as much as you can on the client side. Because it's client-side and javascript... it's immediate.

                  Utilizing the class functions is great... that's just a steal from how Alpha does it. You can go with a pop-up message... or setting text in a static control and then displaying that control. You have many options to get the message out to the user.

                  Comment


                    #10
                    Re: Validation Of One Field 'OR' Another Field

                    Hi David,

                    Just curious, how did you unearth these class methods: $acn, $sa, $rcn ?
                    I can't seem to find any info on them, at least after searching documentation and wiki.

                    Thanks,
                    Stephen
                    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                    Comment


                      #11
                      Re: Validation Of One Field 'OR' Another Field

                      In the documentation search for Javascript. In the list you'll see 2 entries that start "Alpha Five Javascript Libraries..." The 'core' entry has further links. Selwyn uses these often in his videos and the Javascript Libraries are mentioned throughout the release notes.

                      $acn and the others are very welcome functions. They are wrappers for existing javascript functionality.

                      E.g. to add a class using javascript...

                      Code:
                      var ele = document.getElementById('myDiv');
                        if(ele) {
                          ele.className += el.className ? ' myNewClass' : 'myNewClass';
                        }
                      This grabs the div using .getElementById and assigns it to ele. If ele exists then... if the element already has a class it appends the new class... otherwise it just adds the class.

                      .className is the attribute of the ele that you're setting. Same way you'd set .innerHTML.

                      Comment


                        #12
                        Re: Validation Of One Field 'OR' Another Field

                        Thank you.
                        Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                        Comment

                        Working...
                        X