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

Javascript to populate button list

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

  • Javascript to populate button list

    Has anyone succeeded using javascript to populate a Button List?

    I've tried setting the button list for various data sources. It seems the most appropriate to use static JSON but no matter what I do the behavior is the same. Here's the static JSON that Alpha offers as a simple example, and it works as sample JSON:

    Code:
            [
                {html: 'Button A', value: 'b1', tip: 'Help for button 1'},
                {html: 'Button B', value: 'b2', tip: 'Help for button 2'},
                {html: 'Button 3', value: 'b3', tip: 'Help for button 3'}
            ]
    So, I need to dynamically populate (yes, from javascript, not Xbasic) the Button List. And no matter what I do, including this, I get about 60 buttons instead all labelled "undefined".

    Code:
                var jsData = '[';
                jsData = jsData + '{html: \'Button A\', value: \'b1\', tip: \'Help for button 1\'},'
                jsData = jsData + '{html: \'Button B\', value: \'b2\', tip: \'Help for button 2\'},'
                jsData = jsData + '{html: \'Button Q\', value: \'b3\', tip: \'Help for button 3\'}'
    
                jsData = jsData + ']';
                var data = jsData;
                var obj = {dialog.object}.getControl('R_ButtonList');
                obj.populate(data);
                obj.setValue(false);
                alert(data);
    My video reference for this is Number UX_V12-50

    Obviously I need to plug in some data and values other than what I'm trying, but that's useless until I get this basic model correct. So, anyone see what I'm doing wrong?
    -Steve
    sigpic

  • #2
    Re: Javascript to populate button list

    Give this a try:

    Code:
    var obj = {dialog.object}.getControl('R_ButtonList');
    			var jsData = [
    				            {html: 'Button A', value: 'b1', tip: 'Help for button 1'},
                			            {html: 'Button B', value: 'b2', tip: 'Help for button 2'},
                			            {html: 'Button 3', value: 'b3', tip: 'Help for button 3'}
    				           ]
    				obj.populate(jsData);

    Comment


    • #3
      Re: Javascript to populate button list

      Originally posted by Steve Workings View Post
      Has anyone succeeded using javascript to populate a Button List?

      I've tried setting the button list for various data sources. It seems the most appropriate to use static JSON but no matter what I do the behavior is the same. Here's the static JSON that Alpha offers as a simple example, and it works as sample JSON:

      Code:
              [
                  {html: 'Button A', value: 'b1', tip: 'Help for button 1'},
                  {html: 'Button B', value: 'b2', tip: 'Help for button 2'},
                  {html: 'Button 3', value: 'b3', tip: 'Help for button 3'}
              ]
      So, I need to dynamically populate (yes, from javascript, not Xbasic) the Button List. And no matter what I do, including this, I get about 60 buttons instead all labelled "undefined".

      Code:
                  var jsData = '[';
                  jsData = jsData + '{html: \'Button A\', value: \'b1\', tip: \'Help for button 1\'},'
                  jsData = jsData + '{html: \'Button B\', value: \'b2\', tip: \'Help for button 2\'},'
                  jsData = jsData + '{html: \'Button Q\', value: \'b3\', tip: \'Help for button 3\'}'
      
                  jsData = jsData + ']';
                  var data = jsData;
                  var obj = {dialog.object}.getControl('R_ButtonList');
                  obj.populate(data);
                  obj.setValue(false);
                  alert(data);
      My video reference for this is Number UX_V12-50

      Obviously I need to plug in some data and values other than what I'm trying, but that's useless until I get this basic model correct. So, anyone see what I'm doing wrong?

      Hi Steve,

      You're passing a string into populate when you need to give it a JSON object. Try this instead:
      Code:
      var jsData = [];
      jsData.push({html: 'Button A', value: 'b1', tip: 'Help for button 1'});
      jsData.push({html: 'Button B', value: 'b2', tip: 'Help for button 2'});
      jsData.push({html: 'Button Q', value: 'b3', tip: 'Help for button 3'});
      
      var obj = {dialog.object}.getControl('R_ButtonList');
      obj.populate(jsData);
      obj.setValue(false);
      Good luck!
      Alpha Anywhere latest pre-release

      Comment


      • #4
        Re: Javascript to populate button list

        Thanks both for your help.

        Using Sarah's suggestion here, I need to construct the buttons from variables. In what I'm doing below, I do know my array is correct and the loop is correct. But how do I construct the string to push into the array? (Yes, I need to fill the value too, but one thing at a time).

        Code:
        			var jsData = [];
        			for (var i = 0; i < arrayLength; i++) {
        			    var txt = '{html: \'' + parts[i] + '\', value: \'b1\'}';
        				jsData.push(txt);
        			}
        This gets me the correct number of buttons in the control, but they're all labelled "undefined".
        -Steve
        sigpic

        Comment


        • #5
          Re: Javascript to populate button list

          Originally posted by Steve Workings View Post
          Thanks both for your help.

          Using Sarah's suggestion here, I need to construct the buttons from variables. In what I'm doing below, I do know my array is correct and the loop is correct. But how do I construct the string to push into the array? (Yes, I need to fill the value too, but one thing at a time).

          Code:
          			var jsData = [];
          			for (var i = 0; i < arrayLength; i++) {
          			    var txt = '{html: \'' + parts[i] + '\', value: \'b1\'}';
          				jsData.push(txt);
          			}
          This gets me the correct number of buttons in the control, but they're all labelled "undefined".
          Close. You're still creating a string instead of an object. You don't need to construct it as a string. You can put the variables directly in the object:

          Code:
          var jsData = [];
          
          for (var i = 0; i < arrayLength; i++) {
              var button_definition = {html: parts[i], value: 'b1'};
              jsData.push(button_definition)
          }
          If it's easier to think of things like this, then maybe try this approach instead:
          Code:
          var jsData = [];
          
          for (var i = 0; i < arrayLength; i++) {
              var button_definition = {};
              button_definition.html = parts[i];
              button_definition.value = 'b1';
          
              jsData.push(button_definition);
          }
          Last edited by TheSmitchell; 03-24-2016, 03:53 PM. Reason: had a typo
          Alpha Anywhere latest pre-release

          Comment


          • #6
            Re: Javascript to populate button list

            Steve, you are still trying to pass strings instead of JSON objects.

            Code:
            var jsData = [];
            			for (var i = 0; i < arrayLength; i++) {
            			    var txt = {html: parts[i], value: 'b1'};
            				jsData.push(txt);
            			}

            She beat me to it :P

            Comment


            • #7
              Re: Javascript to populate button list

              Thanks. That top one works well, and is very simple once done. But coming from an Xbasic background this is, to say the least, a little "different" to put together a string that's not a string.

              Code:
              var txt = {html: parts[i], value: parts[i]};
              jsData.push(txt);
              -Steve
              sigpic

              Comment


              • #8
                Re: Javascript to populate button list

                Originally posted by Steve Workings View Post
                Thanks. That top one works well, and is very simple once done. But coming from an Xbasic background this is, to say the least, a little "different" to put together a string that's not a string.

                Code:
                var txt = {html: parts[i], value: parts[i]};
                jsData.push(txt);
                It's because you're not building a string. You're building an array of objects with properties. ;)

                The better comparison is to an Xbasic P variable. In Xbasic, you might do something like this:
                Code:
                dim myVar as p
                myVar.prop1 = "property1"
                myVar.isTrue = .t.
                myVar.someNum = 12
                The javascript equivalent would be this:
                Code:
                var myVar = {};
                myVar.prop1 = "property1";
                myVar.isTrue = true;
                myVar.someNum = 12;
                ...which is identical to doing this:
                Code:
                var myVar = {prop1: "property1", isTrue: true, someNum: 12};
                Good luck!
                Alpha Anywhere latest pre-release

                Comment


                • #9
                  Re: Javascript to populate button list

                  OK, one more question and I think I'll be on the way.

                  How do I reference the value of a control in a repeating section as I do this? I've tried all sorts of approaches and can't find the magic combination. This loop works through a repeating section, then appends rows to a List control.

                  Code:
                  	var jsData = [];
                  	var _d = {};
                  	for (var i = 1; i < rowcount; i++) {
                  		_d.rslt_inmodRecordId = 1;
                  		_d.rslt_ques_RecordID = 4;
                  		var fld = 'R_ButtonList:' + i;
                  		_d.rslt_Choice = {dialog.object}.getValue(fld);		// this does not work -- what does?
                  		jsData.push(_d);
                  	}
                  	listObj.appendRows(jsData);
                  -Steve
                  sigpic

                  Comment


                  • #10
                    Re: Javascript to populate button list

                    Originally posted by Steve Workings View Post
                    OK, one more question and I think I'll be on the way.

                    How do I reference the value of a control in a repeating section as I do this? I've tried all sorts of approaches and can't find the magic combination. This loop works through a repeating section, then appends rows to a List control.

                    Code:
                    	var jsData = [];
                    	var _d = {};
                    	for (var i = 1; i < rowcount; i++) {
                    		_d.rslt_inmodRecordId = 1;
                    		_d.rslt_ques_RecordID = 4;
                    		var fld = 'R_ButtonList:' + i;
                    
                    		_d.rslt_Choice = {dialog.object}.getValue(fld);		// this does not work -- what does?
                    
                    		jsData.push(_d);
                    	}
                    	listObj.appendRows(jsData);
                    {dialog.object}.getValue can be used to get the value of a control in a Repeating section. However, you need to call the method _repeatingSectionLogicalToPhysicalRow before calling getValue. For example, suppose you had a repeating section called REPEATINGSECTION_1 with a field called SUBJECT. You could generate the JSON to populate the button list like so:

                    Code:
                    var numRows = {dialog.object}._getRepeatingSectionRowCount('REPEATINGSECTION_1');
                    var _d = [];
                    for (var i = 1; i <= numRows; i++) {
                    
                    	var rowNum = {dialog.object}._repeatingSectionLogicalToPhysicalRow('REPEATINGSECTION_1',i);
                    
                            var button_definition = {};
                            button_definition.html = {dialog.object}.getValue('SUBJECT:'+rowNum);
                            button_definition.value = rowNum;
                    
                    	_d.push(button_definition);
                    }
                    
                    var obj = {dialog.object}.getControl('R_ButtonList');
                    obj.populate(_d);
                    _getRepeatingSectionRowCount returns the number of visible rows (doesn't count deleted rows.)

                    _repeatingSectionLogicaToPhysicalRow converts the logical row number to its physical representation. This is necessary because deleting a repeating section row doesn't re-number the control IDs. So if you have 4 rows, delete 2 rows and add a new row, you will have 3 logical rows however all controls in the new row will be of the format 'FIELDNAME:5', not 'FIELDNAME:3'.

                    Other question:

                    Are the columns in your list control named "rslt_inmodRecordId", "rslt_ques_RecordID", and "rslt_Choice"?
                    Alpha Anywhere latest pre-release

                    Comment


                    • #11
                      Re: Javascript to populate button list

                      Thanks, but I think this is backwards.

                      I am looping through a repeating section. Getting values of the fields, to populate a list control.

                      Yes, I'm aware of and understand the issues with repeating section rows.

                      So I would think this might work, but it does not. If I hard code values, I'm fine. But how to get the value of a control in repeating section Row i ?
                      Code:
                      	_d.rslt_inmodRecordId = 1;
                      	_d.rslt_ques_RecordID = 4;	
                      	var fld_definition = {};
                              fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                              _d.rslt_Choice = fld.definition.html;
                      And yes, those are my list control field names. Customer's naming convention for a big Sage system.
                      -Steve
                      sigpic

                      Comment


                      • #12
                        Re: Javascript to populate button list

                        Originally posted by Steve Workings View Post
                        Thanks, but I think this is backwards.

                        I am looping through a repeating section. Getting values of the fields, to populate a list control.

                        Yes, I'm aware of and understand the issues with repeating section rows.

                        So I would think this might work, but it does not. If I hard code values, I'm fine. But how to get the value of a control in repeating section Row i ?
                        Code:
                        	_d.rslt_inmodRecordId = 1;
                        	_d.rslt_ques_RecordID = 4;	
                        	var fld_definition = {};
                                fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                                _d.rslt_Choice = fld.definition.html;
                        And yes, those are my list control field names. Customer's naming convention for a big Sage system.
                        Great!

                        This should be the way to do it: {dialog.object}.getValue('R_ButtonList:'+rowNum);

                        When are you iterating through the repeating section? Is it a button click? Or is this being done in a client-side event? I find it concerning that this is not working for you.

                        I did notice just now that the for loop you had used a <. The repeating section indexes on 1, so you'll want to change that to <=, but that doesn't answer why it isn't returning a value.
                        Alpha Anywhere latest pre-release

                        Comment


                        • #13
                          Re: Javascript to populate button list

                          Originally posted by Steve Workings View Post
                          Thanks, but I think this is backwards.

                          I am looping through a repeating section. Getting values of the fields, to populate a list control.

                          Yes, I'm aware of and understand the issues with repeating section rows.

                          So I would think this might work, but it does not. If I hard code values, I'm fine. But how to get the value of a control in repeating section Row i ?
                          Code:
                          	_d.rslt_inmodRecordId = 1;
                          	_d.rslt_ques_RecordID = 4;	
                          	var fld_definition = {};
                                  fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                                  _d.rslt_Choice = fld.definition.html;
                          And yes, those are my list control field names. Customer's naming convention for a big Sage system.
                          Also, the last line should probably be fld_definition.html, not fld.definition.html:
                          Code:
                          	_d.rslt_inmodRecordId = 1;
                          	_d.rslt_ques_RecordID = 4;	
                          	var fld_definition = {};
                                  fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                          [B]        _d.rslt_Choice = fld_definition.html;
                          [/B]
                          Alpha Anywhere latest pre-release

                          Comment


                          • #14
                            Re: Javascript to populate button list

                            Last Q. first: I have my reasons for looping through a repeating section to populate a list. Customer will probably bring this to AlphaDev and show it off.

                            So, here's where I am. The alert() shows the correct value. But it's still not populating that column in the List control. The hard-coded values of 1 and 4 above that are populating just fine. Something off in syntax - does it need single quotes? The return value is character type.

                            Code:
                            	var jsData = [];
                            	var _d = {};
                            	for (var i = 1; i <= rowcount; i++) {
                            		
                            		var rowNum = {dialog.object}._repeatingSectionLogicalToPhysicalRow('RS_GENERALCONDITIONS',i);
                            		
                            		_d.rslt_inmodRecordId = 1;
                            		_d.rslt_ques_RecordID = 4;
                            
                            		var fld_definition = {};
                            	     	 fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                            	        _d.rslt_Choice = fld_definition.html;
                            		alert(_d.rslt_Choice);
                            		
                            		jsData.push(_d);
                            	}
                            	listObj.appendRows(jsData);
                            -Steve
                            sigpic

                            Comment


                            • #15
                              Re: Javascript to populate button list

                              Originally posted by Steve Workings View Post
                              Last Q. first: I have my reasons for looping through a repeating section to populate a list. Customer will probably bring this to AlphaDev and show it off.

                              So, here's where I am. The alert() shows the correct value. But it's still not populating that column in the List control. The hard-coded values of 1 and 4 above that are populating just fine. Something off in syntax - does it need single quotes? The return value is character type.

                              Code:
                              	var jsData = [];
                              	var _d = {};
                              	for (var i = 1; i <= rowcount; i++) {
                              		
                              		var rowNum = {dialog.object}._repeatingSectionLogicalToPhysicalRow('RS_GENERALCONDITIONS',i);
                              		
                              		_d.rslt_inmodRecordId = 1;
                              		_d.rslt_ques_RecordID = 4;
                              
                              		var fld_definition = {};
                              	     	 fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                              	        _d.rslt_Choice = fld_definition.html;
                              		alert(_d.rslt_Choice);
                              		
                              		jsData.push(_d);
                              	}
                              	listObj.appendRows(jsData);
                              Ah. I just figured out what's going on.

                              Move your declaration for _d inside the for loop:

                              Code:
                              	var jsData = [];
                              	for (var i = 1; i <= rowcount; i++) {
                              		var _d = {};
                              		
                              		var rowNum = {dialog.object}._repeatingSectionLogicalToPhysicalRow('RS_GENERALCONDITIONS',i);
                              		
                              		_d.rslt_inmodRecordId = 1;
                              		_d.rslt_ques_RecordID = 4;
                              
                              		var fld_definition = {};
                              	     	 fld_definition.html = {dialog.object}.getValue('R_ButtonList:'+rowNum);
                              	        _d.rslt_Choice = fld_definition.html;
                              		alert(_d.rslt_Choice);
                              		
                              		jsData.push(_d);
                              	}
                              	listObj.appendRows(jsData);
                              In the push operation, it's adding _d, but because _d is declared outside the for loop, when you modify _d on subsequent iterations, it's just updating the same variable. push keeps pushing the same variable. It won't make a copy like you would expect. I'm not well versed enough in Javascript to explain this effectively. Stackoverflow has a few threads that may be of use: http://stackoverflow.com/questions/1...hing-an-object and http://stackoverflow.com/questions/1.../111200#111200.

                              Moving _d inside the for loop will create the behavior you want. It'll produce a new "instance" of _d on each loop. You can test this by changing one of your hard-coded fields to reference the i variable instead. It should be identical to rowcount for every record if _d is declared outside the loop and increment for every record if _d is declared inside the loop.
                              Alpha Anywhere latest pre-release

                              Comment

                              Working...
                              X