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

Trouble With Conditional Formatting and Zero Values

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

  • Trouble With Conditional Formatting and Zero Values

    I'm trying to use basic client-side conditional formatting on a numeric textbox, but it is not co-operating when the value is zero.

    My criteria is simple:
    1) Background RED when value is <-2 or >2 or <value> is ""
    2) Background BLUE when value is >=-2 and <=2

    The problem is when the value is 0, the background is set to Red and it should be Blue.
    No matter what I do, I can't seem to fix this. I've tried playing with allow blank values and setting the blank value as something like -9999 (thinking it was treating 0 as blank), but that won't work either.

    I've attached a very simple example. It only has one textbox on it. If 0 is entered, the box goes Red which is not what I want.

    If anyone is able to take a look, I could use the help.
    Attached Files
    Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

  • #2
    Re: Trouble With Conditional Formatting and Zero Values

    Conditional formatting is a bit tricky because I'm not sure how/when formatting is evaluated. When faced with a somewhat intricate set of choices I'll turn to a function instead... you have far more control.

    For example, using a function and passing in the field 'textbox1' we would see that textbox1 always has a value of 0... even though it shows as empty. So... even though we pass in the value, we're not going to use it. Instead, go after textbox1 inside the function and get it's true value.

    So... your conditions would now be...

    Code:
    condText1(textbox1)=false (this is the red one)
    condText1(textbox1)=true (this is the blue one)
    and your Javascript function "condText1" is...

    Code:
    function condText1(tb1){
    
    	var textbox1 = {dialog.Object}.getValue('textbox1');
    	
    	if(textbox1 != ''){
    		textbox1 = Number(textbox1);
    	}
    	
    	if(textbox1 < -2 || textbox1 > 2 || textbox1 === ''){
    			return false;
    	}else{
    		return true;
    		}
    	}
    
    }
    Grab the value for textbox1. If it's not '' then convert it to a number.

    If the value falls out of range... or it's '' then return false. Notice we test for value and type regarding '' using ===.
    Else... return true.
    Last edited by Davidk; 04-25-2017, 09:25 PM.

    Comment


    • #3
      Re: Trouble With Conditional Formatting and Zero Values

      Wow, that is very cool. Works perfectly!

      Thanks very much David, I learned something
      Last edited by iRadiate; 04-25-2017, 08:01 PM.
      Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

      Comment


      • #4
        Re: Trouble With Conditional Formatting and Zero Values

        Well, I've run into a problem with this that I can't seem to avoid.

        If the user sets focus to the textbox and then tabs out of the textbox without entering a value, the code places a '0' in the textbox and it remains red (as though there were no value present).
        If the user actually puts a '0' into the textbox, the formatting is blue (which is correct ... any value between -2 and 2 should be blue).

        Because this is on a data entry form, I do not want a '0' showing in the textbox if the user just tabs through it.

        Are there any thoughts on how to work around this? Simple example is attached.
        Attached Files
        Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

        Comment


        • #5
          Re: Trouble With Conditional Formatting and Zero Values

          So the problem here seems to be that I am applying client side formatting so that the number displays with 2 decimal places. When the user tabs out without entering a value, I get 0.00 in the box (BAD):

          2017-06-08_12-49-14.png -----> 2017-06-08_12-57-33.png


          But if I remove the client-side formatting and do it server-side then there is no value placed in the textbox when the user tabs out without entering a value (GOOD):

          2017-06-08_12-51-47.png -----> 2017-06-08_13-03-33.png



          If the user enters a value, there is no decimal place formatting (because it's server side now): -----> 2017-06-08_13-04-51.png

          I can live with this, though it would be nice is there were a way to force 2 decimal places
          Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

          Comment


          • #6
            Re: Trouble With Conditional Formatting and Zero Values

            Then it's time to go it alone... and remove your Client-side formatting and the Conditional Style.
            Set the Style of the TextBox to have a background color of red... this is the default, empty setting.

            In the TextBox onChange event...

            Code:
            condText("textbox1");
            And the Javascript function, condText, is...

            Code:
            function condText(tbCtrl){
            
            	var tbEle = {dialog.Object}.getPointer(tbCtrl);
            	var tbVal = tbEle.value;
            	
            	if(tbVal == ""){
            		tbEle.style.backgroundColor = 'red';
            		return;
            	}
            	
            	tbVal = Number(tbVal);
            	
            	if(tbVal < -2 || tbVal > 2){
            		tbEle.style.backgroundColor = 'red';
            		tbVal = tbVal.toFixed(2);
            		{dialog.Object}.setValue(tbCtrl,tbVal,false);	
            		return;
            	}
            
            	if(tbVal >= -2 && tbVal <= 2){
            		tbEle.style.backgroundColor = '#99ccff';
            		tbVal = tbVal.toFixed(2);
            		{dialog.Object}.setValue(tbCtrl,tbVal,false);	
            		return;
            	}
            
            }
            Here we get a pointer to the "TextBox" control passed in... and we get it's value.

            Then we first test for an empty string. If it's empty then we set the bgcolor to red and return.
            And so on.

            If you just tab in and out of a TextBox, onChange doesn't fire at all... so in your case, empty and red with stay that way.

            Now... if this is databound... and you want to show the proper color when rendered, then in Client-side onRenderComplete you'll need to call the condText function for each TextBox set up like this.
            Attached Files

            Comment


            • #7
              Re: Trouble With Conditional Formatting and Zero Values

              *thanks for the example and code - I just hope I remember where to find this when I actually want to set colors in this way, especially when rendered!
              NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

              Comment


              • #8
                Re: Trouble With Conditional Formatting and Zero Values

                David, once more I have to say thank you for sharing your code example, that works great! I was attempting a similar approach but getting nowhere with it so this is really helpful.
                This is a really useful piece of code for data entry applications.

                Yes, my textboxes are data-bound so I will be sure to call the function in the onRenderComplete when showing the completed forms.
                Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                Comment


                • #9
                  Re: Trouble With Conditional Formatting and Zero Values

                  FYI,

                  Just a quick addition to this thread, I found that I had to call the condText functions when rendering the UX component from afterPopulateFromTable client-side event rather than onRenderComplete.
                  Otherwise the conditional formatting only gets applied the first time you select a record from the list, not on subsequent selections.
                  Alpha Anywhere v12.4.6.2.5 Build 7086-5534 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                  Comment


                  • #10
                    Re: Trouble With Conditional Formatting and Zero Values

                    Nice... thanks.
                    Last edited by Davidk; 06-11-2017, 03:51 PM.

                    Comment


                    • #11
                      Re: Trouble With Conditional Formatting and Zero Values

                      I think the best way to handle this is to set up a Watch event on that control. Then you never have to worry about bound/unbound, data loading, navigating records... nothing. Whenever the value in that control changes, either from user input, or loading or navigation... the Watch event fires, and your control is formatted properly.

                      Comment

                      Working...
                      X