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

Enforce validation only if; show popup list

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

    Enforce validation only if; show popup list

    I've done this very easily on the desktop side using xbasic, but I'm stumped on how to do this on the client side using javascript.

    I have a UX component with a number of required fields. If the Status field is Pending or Void, the required fields do not need to be filled in. However; if the user tries to change the Status to Ordered, I want to stop the change if the required fields are Not filled in.

    Initially, I started with a lookup edit-combo for the Status field, but there is only a OnChange event. I want to prevent any change, not wait until a change has been made.

    So then I tried a button to change the Status. The following code works well to stop the change. But I can't figure out how to create a simple select list to pass the new choice to the Status field.

    Code:
    var poStatus = {dialog.Object}.getValue('STATUS');
    
    //check that status <> pending AND status <> Void
    if (poStatus != "PENDING" && poStatus != "VOID") {
    	var controlsToValidate = ['PDATE','REQ_FOR','TAIL_NUM','V1','S1','SHIP_HOW','REQ_BY','APPROVE','WRITTEN'];
    	var flagHasError = false;
    	var result = '';
    	
    	for (var i = 0; i < controlsToValidate.length; i++) {
    	    result = {dialog.object}.clientSideValidateField(controlsToValidate[i],1);
    	if(typeof result == 'string') flagHasError = true;
    	}
    }
    
    //if all required fields have been filled in, open a list of choices picking just one to be entered into the status field
    // Choices:  pending, ordered, received, Void, a blank line, Posted
    //after selecting one, set the new value in the status field and do a ajaxcallback to write the new value to the table
    
    //{dialog.Object}.showContainerWindow(ele,'STATUS_CHOICES');
    
    //alert("OK");
    
    //{dialog.Object}.setValue('STATUS',value [,honorChangeEvent] );
    //{dialog.object}.ajaxCallback('','','ChangeStatus','','',{deviceOfflineFunction: function() {   }});
    Not sure what to do next. I have spent 2 days on this and right now I'm mentally exhausted.
    Attached Files
    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: Enforce validation only if; show popup list

    I kinda understand... but not really.

    if the user tries to change the Status to Ordered, I want to stop the change
    Ok... I get this.

    and

    I want to prevent any change, not wait until a change has been made.
    I don't get this.

    I can change Status to Pending and the callback will fire.

    If I change Status to Ordered... and the Required Fields are not filled in... change Status back to what it was... and do not fire the Callback. Is that what you want?

    Also, it'd be nice to know how the Required Fields are being validated.
    Last edited by Davidk; 06-02-2017, 07:30 PM.

    Comment


      #3
      Re: Enforce validation only if; show popup list

      I would still use the onchange event. I'd just change it back. Something like:
      if(status == 'Ordered' && RequiredField ==''){
      set the value back to 'Pending'
      alert('Ordered is not allowed will RequiredFiled is blank');
      }

      Comment


        #4
        Re: Enforce validation only if; show popup list

        Let me start over.

        We have a purchase order. Initially, only the header is created with minimal information. At that point the Status of the PO is PENDING. When the PO is completed (meaning the items on the PO have been ordered), the Status is then to be changed to ORDERED.

        You may find this hard to believe, but PO's with nothing but a date and a parts list have been marked as ORDERED.

        Therefore, we are checking that 9 different fields have been filled in Before the PO's status may be changed to ORDERED. Things like Vendor, who ordered the parts, where shipped to, etc...

        On my desktop app, this was a very simple xbasic script that handled this.

        I'm trying to figure out how to do the same in a WEB app.

        First: I have created client side only validations for the 9 required fields. But this requires the fields be filled in any time the dialog is saved. I only want the validation in force when the status of the PO is changed to ORDERED, RECEIVED and POSTED. As long as the Status is PENDING or VOID, the validation is not needed.

        Second: Before the Status of the PO can be changed to ORDERED, RECEIVED or POSTED, the 9 required fields must be filled in. Or to phrase this another way, when changing the Status from PENDING or VOID to ORDERED, RECEIVED or POSTED, if the 9 required fields are not filled in, Stop the Status change and notify the user that the required fields need to be filled in.

        I guess what I'm looking for is a canChange event on the edit-combo control 'Status'. All I have is an onChange event.

        I see that there is Validation xbasic, Validation rules (which is what I'm using) and Validation Javascript. Not sure how to use them all. I just found a number of videos about validation which I'm going to watch. Maybe there's something in there that will help.

        Right now this is the code I have in the onChange event of the control STATUS.

        Code:
        var poStatus = {dialog.Object}.getValue('STATUS');
        
        //check that status <> pending AND status <> Void
        if (poStatus != "PENDING" && poStatus != "VOID") {
        	var controlsToValidate = ['PDATE','REQ_FOR','TAIL_NUM','V1','S1','SHIP_HOW','REQ_BY','APPROVE','WRITTEN'];
        	var flagHasError = false;
        	var result = '';
        	
        	for (var i = 0; i < controlsToValidate.length; i++) {
        	    result = {dialog.object}.clientSideValidateField(controlsToValidate[i],1);
        	if(typeof result == 'string') flagHasError = true;
        	}
        }
        
        if(typeof result == 'string') {
        	alert("Required Field(s) Are Blank");
        } else {
        	{dialog.object}.ajaxCallback('','','ChangeStatus','','',{deviceOfflineFunction: function() {   }});
        }
        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


          #5
          Re: Enforce validation only if; show popup list

          I'd try it this way. In your Status onChange event, add a call to a Javascript function...

          Code:
          checkStatus(this.value);
          Then add your Javascript function to the Javascript functions section...

          Code:
          function checkStatus(poStatus){
          	
          var flagHasError = false;
          
          //check that status <> pending AND status <> Void
          if (poStatus != "PENDING" && poStatus != "VOID") {
          	var controlsToValidate = ['PDATE','REQ_FOR','TAIL_NUM','V1','S1','SHIP_HOW','REQ_BY','APPROVE','WRITTEN'];
          	
          	for (var i = 0; i < controlsToValidate.length; i++) {
          	    var ctrlValue = {dialog.Object}.getPointer(controlsToValidate[i]).value;
          	    if(ctrlValue == ''){
          	    	flagHasError = true;
          	    	break;
          	    }
          	}
          	
          }
          
          if(flagHasError){
          	alert("Required Field(s) Are Blank");
          	{dialog.Object}.setValue('STATUS',{dialog.Object}.originalValues[0].STATUS,false);
          } else {
          	{dialog.object}.ajaxCallback('','','ChangeStatus','','',{deviceOfflineFunction: function() {   }});
          }
          Loop through your array of controls to check. If one of them turns up empty, set your error flag and then break to get out of the loop. No sense checking for other empty controls... unless you want to.

          if the error flag is true, send out a mesage and then set the Status control value back to it's original.

          Checking a control for a value can mean lots of things... here we're just checking for an empty string.

          Edited to clean up a bit.
          Last edited by Davidk; 06-03-2017, 01:10 PM.

          Comment


            #6
            Re: Enforce validation only if; show popup list

            You should probably use David's excellent code, but this is a quick video to show the longhand version. https://www.screencast.com/t/mwVCzG2j

            Comment


              #7
              Re: Enforce validation only if; show popup list

              I made a quick update: https://www.screencast.com/t/1E1VFBq8NE9B

              Comment


                #8
                Re: Enforce validation only if; show popup list

                David,

                As always your answer are super. I've attached my latest code. You'll notice that I couldn't use getpointer, didn't work,
                so I changed to getValue.

                Code:
                function checkStatus(poStatus){
                
                //Loop through your array of controls to check. If one of them turns up empty,
                //set your error flag and then break to get out of the loop. No sense checking for other empty controls... unless you want to.
                
                //if the error flag is true, send out a mesage and then set the Status control value back to it's original.
                
                //Checking a control for a value can mean lots of things... here we're just checking for an empty string.
                
                var flagHasError = false;
                	
                //check that status <> pending AND status <> Void
                if (poStatus != "PENDING" && poStatus != "VOID") {
                	var controlsToValidate = ['PDATE','REQ_FOR','TAIL_NUM','V1','S1','SHIP_HOW','REQ_BY','APPROVE','WRITTEN'];
                
                	for (var i = 0; i < controlsToValidate.length; i++) {
                		var ctrlValue = {dialog.object}.getValue(controlsToValidate[i]);
                		if(ctrlValue == ''){
                			flagHasError = true;
                			break;
                		}
                	}
                }			
                
                if(flagHasError) {
                	A5.msgBox.show('Oops','<div style="height: .5in; padding: 15pt;"><font size="4">Required Fields are Blank</font></div>',[{html: 'OK', value: 'ok'}],function(button) {if(button == 'ok') {
                	setTimeout(function() {},10)
                	}
                	});
                	{dialog.object}.setValue('STATUS',{dialog.object}.originalValues[0].STATUS,false);
                } else {
                	{dialog.object}.ajaxCallback('','','ChangeStatus','','',{deviceOfflineFunction: function() {   }});
                }
                
                }
                Lee,

                Thanks so much. Great examples.

                I'm still having an issue with setting the value of STATUS back to pending. I'm using a lookup in a control based on an edit-combo box. Lee, are
                you using a list?

                I'm using a control bound to the backend table. I'm using watermarks in red ("Required Field") to highlight all the required fields.
                Last edited by Ronald Anusiewicz; 06-03-2017, 03:57 PM. Reason: Pressed the wrong button before I was finished
                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


                  #9
                  Re: Enforce validation only if; show popup list

                  Lee,

                  Thanks so much for your videos. All I had to do is change the control from a textbox to a DropDownBox and it working.
                  Last edited by Ronald Anusiewicz; 06-03-2017, 04:13 PM. Reason: Spelling, what else.
                  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


                    #10
                    Re: Enforce validation only if; show popup list

                    .getValue()... even better.

                    The problem with setting the Edit-Combo List back to it's original value is probably because you have the property checked... "User must select from list". This means exactly what it says... unfortunately. Not only the user... but us... via code... as well. We cannot use .setValue() while this property is checked.

                    You'll need uncheck that property and then validate the selected choice.

                    Your Status onChange Event code could do this...

                    Code:
                    var validStatus = ["PENDING","ORDERED","RECEIVED","VOID","POSTED"];
                    if(validStatus.indexOf(this.value)!=-1){
                    	checkStatus(this.value);
                    }else{
                    	alert('Please make a selection from the dropdown list');
                    	{dialog.Object}.setValue('STATUS',{dialog.Object}.originalValues[0].STATUS,false);
                    }
                    If you're not hung up on an Edit-Combo, the DropDownBox control is easier to work with in these cases.
                    Last edited by Davidk; 06-03-2017, 04:37 PM.

                    Comment


                      #11
                      Re: Enforce validation only if; show popup list

                      Thanks again David. Was a very educational post. Your right about "User must select from List" being selected. I'm sticking with the DropDownBox.
                      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: Enforce validation only if; show popup list

                        Glad it all worked. Yes... just read that about the DropDownBox. Nice to have a choice.

                        Comment

                        Working...
                        X