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

Mask for textbox that holds phone number

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

    Mask for textbox that holds phone number

    Hi There,

    Thank you for having a look.

    Do you know how to set a mask that depends on the first two numbers entered into a textbox?

    For instance, if a textbox is a phone number, and the person has entered 04 then we want the mask for that textbox to be 0000 0000
    But if the first two letters are 08 then we want the mask to be 00 0000 0000

    Thanks

    Jane.

    #2
    Re: Mask for textbox that holds phone number

    What I did was create a User Defined Function called format_phone(input_number) that returns the number in the correct format. That way you can test and manipulate to your heart's content.
    Pat Bremkamp
    MindKicks Consulting

    Comment


      #3
      Re: Mask for textbox that holds phone number

      You want to start typing into textbox1 and as you enter text you'd like the mask to adjust depending on text you're entering?

      Comment


        #4
        Re: Mask for textbox that holds phone number

        Thanks Pat. That helps to know that's what you done.
        David, yes, that's correct. As we start typing into a textbox1 we'd like the mask to adjust depending on the first two values they're entered.

        Comment


          #5
          Re: Mask for textbox that holds phone number

          There is a way to get this done... but it's a little complex. I'll assume we're working with a UX. There is a feature for the Mask property that allows you to set a dynamic mask. Usually the "dynamic" part depends upon another control, so there's not really an issue. The dynamic mask is set when the control with the mask gets focus. Because we're already in the control we need to get out and come back in. This means setting focus to another control, and then setting focus to your Mask control. And... in your case... only after the first 2 characters have been entered.

          Further, once you're back into the control (done with a .setFocus) you don't want the data already entered to be highlighted. You want your cursor to be positioned at the end of the data already input.

          So, for this to work, you must be ok with having another field around (usually there is anyway). If you need to add a dummy field, then it can be made invisible(ish). You can't hide this extra field... because we need to set focus to it.

          Attached is a test component.

          In Client Side Properties, check on Client side formatting and make sure Format type is set to Mask. Then click into the builder for the Format definition. Set the Mask type to Conditional and enter the name of a Javascript function... e.g. myMask

          Showing the Mask characters doesn't work with this whole process... but... you can't have everything.

          Click OK to save this section.

          In the UX Javascript functions section enter this code...

          Code:
          function myMask(e) {
          
          var ac = {dialog.object}.getValue('textMask');
          ac = ac.substring(0, 2);
          switch(ac){
          	case '04':
          		return '0000 0000';
          		break;
          	case '08':
          		return '00 0000 0000';
          		break;
          	default:
          		return '';
          	}
          			
          }
          This code runs when the control gets focus. We grab what's already been entered, if anything, grab the first 2 characters of that and test it. If it's 04 we return a Mask of 0000 0000. If it's 08 we return a Mask of 00 0000 0000. Anything else we just return... no Mask set.

          Now... back to the control that has the Mask. In the onKeyUp event of this control, put this code...

          Code:
          setTimeout(function(){
          	var myData = {dialog.Object}.getValue('textMask');
          	myData = myData.trim();
          	if(myData.length == 2){
          		var keyID = event.keyCode;
          		switch(keyID){
          			case 8:
          				//backspace key
          				break;
          			default:
          				{dialog.Object}.setFocus('textAC');
          				{dialog.Object}.setFocus('textMask');
          		}
          	}
          },50);
          Every time we release a key this fires. We grab the control value, trim it, test it for a length of 2 and then grab the keyCode of the key just pressed.

          If the key is a backspace then don't do anything. Otherwise, set focus to another control, and then back again to the control with the Mask. Since we now have focus again, the Mask code is fired and tests the input. All this is wrapped in a .setTimeout of 50ms to allow time for the control to recognize that something has been typed.

          Finally, in the onFocus event of this control put this code...

          Code:
          var val = this.value;
          val = val.trim();
          var len = val.length;
          setTimeout(function(){
          	var el = $('{dialog.ComponentName}.V.R1.TEXTMASK');
          	el.setSelectionRange(len, len);
          },25);
          As soon as out Mask control gets focus we grab it's value, trim it, and get it's length. Then we use a great little method called .setSelectionRange which lets us put the cursor where we want. We have to wrap this part is a .setTimeout as well, just to give things a chance to settle down a bit.

          So, in summary, we type, test the input, and if we have typed in data with a length of 2 we get out and come back in. When we come back in Alpha fires off it's Mask code, and we fire off our own focus code to shove the cursor to the end.

          Whew!
          Attached Files

          Comment


            #6
            Re: Mask for textbox that holds phone number

            Whew indeed! But happy whew to finally see it pieced together.
            Thank you David. I wouldn't have thought of doing it that way. Your input and guidance is appreciated.
            We had been trying to edit the mask dynamically by accessing getControl{'phone'}.format.mask and others of similar but this makes more sense.
            We're glad to see how to get it to work.
            Cheers!

            Comment


              #7
              Re: Mask for textbox that holds phone number

              Jane,

              You're idea is way better... so let's use that. I'd like to find a way to steal the mask array and save it. I don't really feel like creating it by hand... so let's set up 2 controls. One with a simple mask of 0000 0000 and the other with a simple mask of 00 0000 0000. I created 2 controls name textMask04 and textMask 08. You can hide these controls.

              We no longer have to play with setFocus... so that's excellent. Delete the code in the onFocus event of the main control.

              The conditional mask on the main control still needs to be set.

              The onKeyUp event code for the main control is now...

              Code:
              setTimeout(function(){
              	var myData = {dialog.Object}.getValue('textMask');
              	myData = myData.trim();
              	if(myData.length == 2){
              		var keyID = event.keyCode;
              		switch(keyID){
              			case 8:
              				//backspace key
              				break;
              			default:
              				setMask(myData);
              		}
              	}
              },50);
              Now, when we're ready to set a new mask, we're calling a Javascript function named setMask and we're passing in our data.

              The setMask function is...

              Code:
              function setMask(myData){
              
              	var ac = myData.substring(0, 2);
              
              	switch(ac){
              		case '04':
              			var el = {dialog.Object}.getControl('textMask');
              			var elNew = {dialog.Object}.getControl('textMask04');
              			var newMask = elNew.format._pMask.mask;
              			el.format._pMask.mask = newMask;			
              			var elMask = $('{dialog.ComponentName}.V.R1.TEXTMASK');
              			elMask.setSelectionRange(2, 2);
              			break;
              		case '08':
              			var el = {dialog.Object}.getControl('textMask');
              			var elNew = {dialog.Object}.getControl('textMask08');
              			var newMask = elNew.format._pMask.mask;
              			el.format._pMask.mask = newMask;			
              			break;
              		default:
              			var el = {dialog.Object}.getControl('textMask');
              			el.format._pMask.mask = "";
              	}
              }
              We getting our data, ensuring it's just the first 2 characters. If it's 04, grab a pointer to our main control. Get a pointer to our Mask04 control and steal it's Mask.
              Set the Mask of our Main control to the Mask of the Mask04 control.

              Same for 08.

              But... in the case of entering 08, and then changing your mind, and entering 04, we need to set the cursor to the end of 04.

              This is much, much nicer.

              EDIT: Have to take care of the Mask... if you don't want a mask... so note the "default" entry in setMask. Remember to update the attached component.
              Attached Files
              Last edited by Davidk; 09-06-2015, 10:23 PM.

              Comment


                #8
                Re: Mask for textbox that holds phone number

                ha ha haaaaaaa! Awesome, that's fantastic David.
                I can see the two lines of code I had wrong previously and why it wasn't working.
                Thank you for sharing - you've put a smile on the dial!
                Thanks again,
                Jane.

                Comment


                  #9
                  Re: Mask for textbox that holds phone number

                  To really hammer this one into the ground... you can create you're own Mask on the fly. To get the format right, create a textbox with the Mask that you want and see what that looks like when rendered and run. Then, copy it.

                  Here's the code to create the 2 masks used in this thread.

                  Code:
                  function setMask2(myData){
                  
                  	var ac = myData.substring(0, 2);
                  
                  	switch(ac){
                  		case '04':
                  			var el = {dialog.Object}.getControl('textMask2');
                  			
                  			var newMask = [];
                  			for(i=0;i<9;i++){
                  				if(i==4){
                  					newMask.push(" ");
                  				}else{					
                  					newMask.push(/[0-9]/);
                  				}
                  			}				
                  			
                  			el.format._pMask.mask = newMask;			
                  			var elMask = $('{dialog.ComponentName}.V.R1.TEXTMASK2');
                  			elMask.setSelectionRange(2, 2);
                  			break;
                  		case '08':
                  			var el = {dialog.Object}.getControl('textMask2');
                  			
                  			var newMask = [];
                  			for(i=0;i<12;i++){
                  				newMask.push(/[0-9]/);
                  			}
                  			newMask[2] = " ";
                  			newMask[7] = " ";				
                  
                  			el.format._pMask.mask = newMask;			
                  			break;
                  		default:
                  			var el = {dialog.Object}.getControl('textMask2');
                  			el.format._pMask.mask = "";
                  		
                  	}
                  }
                  A Mask is an Array. 0000 0000 has 9 elements. The code above loops 9 times and has a test for the 4th (zero based) element.

                  For the Mask 00 0000 0000, which has 12 elements I just set them all to the same value in a loop... and then just changed the 2 that are different. Just another way of getting something done.

                  Using this code, you don't need any other controls.

                  Comment


                    #10
                    Re: Mask for textbox that holds phone number

                    Beautiful. Simple, easy and effective.
                    Thank you David. I think you've thoroughly hammered this one out!
                    It works perfectly and with the exact desired result.
                    Noice.

                    Comment


                      #11
                      Re: Mask for textbox that holds phone number

                      Hey David,
                      Correction, it's not working perfectly on our machine....it's having trouble with the {dialog.object}.getControl as it's not retrieving the control. Do you mind letting me know what version of alpha you are using?
                      Thanks,

                      Comment


                        #12
                        Re: Mask for textbox that holds phone number

                        phonemask.a5wcmp
                        Here's the test comp I'm trying to setup. I'm trying to isolate the javascript function so that it can be put in a common.js file so it can be called from multiple components.

                        It's failing at the getControl and the window.alert is returning false instead of [Object]. FYI pls excuse my window.alerts as that's my way of debugging.

                        Comment


                          #13
                          Re: Mask for textbox that holds phone number

                          Um, I think there might be a bug in our version of Alpha David because when I copied your textbox into my component it started working (yay). But if I place a new textbox in the component and point the mask to work for the new textbox, the getControl code doesn't work.
                          Thanks again for your test components David.

                          Comment


                            #14
                            Re: Mask for textbox that holds phone number

                            Hey Jane,

                            There are 2 issues with your component.

                            1. Add a Mask to your Textbox and then .getControl will work.
                            2. The way you're setting elMask isn't quite right. This code works...

                            Code:
                            var myMask = eval("'" + dialogComponentName + '.V.R1.' + textBoxName.toUpperCase() + "'");
                            var elMask = $(myMask);
                            Since we're using getElementById, we must be very precise. Rendered, the control is 'DLG1.V.R1.PHONE'. The 'PHONE' part is uppercase.

                            Your component works with Alpha release 2999 and 3085.

                            Comment


                              #15
                              Re: Mask for textbox that holds phone number

                              Hey David - yeah I was in the middle of debugging it when I sent it to you but since I wasn't able to get past the getControl part I hadn't yet reached the second error on our part. My apologies.
                              Great - we have it working now. Thank you. Your time and friendly nature is appreciated

                              Comment

                              Working...
                              X