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 Javascript

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

  • Trouble with Javascript

    I am adding records to a repeating section.
    The idea is a check out.
    When I click on the buy button I add a line to the repeating section.
    (I check to see if there are any records, because the first time I have an empty row.)
    In the check out I want to have rows with unique products.
    If I click the same button twice I want to update the quantity not add a new row.

    Selwyn helped me with some of the code and some of the code was found on the message board.
    I have added 2 sets of code together badly.
    I need help to fix it.

    Selwyn's code moves the items from the list to a repeating section.
    First we check the existing row count, if the row count is 1 then we look to see if there is a value in the row.
    If there is a empty row we add the data.
    If there is data in the row we add a new row, then add the data.
    Subsequently we add rows and data.

    In the 'on change event' of the primary key in the repeating section we look to see if there is already a record.
    if there is we add one to the quantity and delete the appended row, if not we append a new row.
    Everything works.
    However if the quantity is changed from 1 to a higher value then the code stops working.

    This is where I think my logic has been misunderstood by JavaScript.
    I have a video showing what happens.

    Here is the JavaScript.

    function Buy() {
    var flagAddRow = true;
    var existingRowCount = {dialog.Object}._getRepeatingSectionRowCount('REPEAT');
    if(existingRowCount == 1){


    var row1val = {dialog.Object}.getValue('Bagel:1')
    if(row1val == '') flagAddRow = false;
    var ele = $('{dialog.componentname}.V.R1.REPEAT');
    A5.u.element.show(ele,{show: {type: 'blind',duration: 'fast'},hide: {type: 'blind',duration: 1000}} );

    }
    if(flagAddRow){

    {dialog.Object}.addRepeatingSectionRow('REPEAT');
    }

    var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
    var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
    var Desc = {dialog.Object}.listGetValue('List1','P_Name');

    {dialog.Object}.setValue('Bagel',Bagel );
    {dialog.Object}.setValue('Price',Price );
    {dialog.Object}.setValue('Description',Desc );
    }
    // This is the code for onchange



    function CheckForDuplicate(ContainerName,FieldName,FieldValue)
    {
    var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);

    CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);


    for (var i=1;i<={dialog.Object}._getRepeatingSectionRowCount(ContainerName);i++)

    {
    var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
    var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);

    if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {

    var Qty = {dialog.object}.getValue('Qty' + ':' + row);

    Qty = +Qty + +1

    {dialog.object}.setValue('Qty' + ':' + row,Qty);

    // I think that the row I want is written and then deleted.
    // If I put in an alert I can see the row created but when I click OK it appears to be deleted.

    {dialog.Object}.deleteRepeatingSectionRow('REPEAT',-1,true);

    }
    }
    }


    My video


    http://www.youtube.com/watch?v=5V6BMKLoXg0

    Thanks Michael

  • #2
    Re: Trouble with Javascript

    It might be easier to change your logic to search for any existing item, increment the count if it does exist, otherwise insert a new row and set the values (or populate the first row if that's the case) rather than always adding a row and subsequently needing to delete it. Then you only need one function...

    Code:
    function Buy()
    {
      var ContainerName = 'REPEAT';
      var FieldName = 'Bagel';
      var FieldValue = {dialog.object}.listGetValue('List1','Prog_Bagel');
    
      var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);
      CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);
      
      var totalRows = {dialog.Object}._getRepeatingSectionRowCount(ContainerName);
      for (var i=1;i<=totalRows;i++) {
        var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
        var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);
    
        if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {
          var Qty = {dialog.object}.getValue('Qty' + ':' + row);
          Qty = Qty + 1;
          {dialog.object}.setValue('Qty' + ':' + row,Qty);
          return; //done; return early
        }
      }
      
      if (totalRows == 1) {
        var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,1);
        var rowValue = {dialog.object}.getValue(FieldName + ':' + row);
        if (rowValue != '') {
          //add a new row
          {dialog.object}.addRepeatingSectionRow(ContainerName);
        }
      } else {
          {dialog.object}.addRepeatingSectionRow(ContainerName);
      }
    
      var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
      var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
      var Desc = {dialog.Object}.listGetValue('List1','P_Name');
    
      {dialog.Object}.setValue('Bagel',Bagel);
      {dialog.Object}.setValue('Price',Price);
      {dialog.Object}.setValue('Description',Desc);
    }
    Alpha Anywhere latest pre-release

    Comment


    • #3
      Re: Trouble with Javascript

      Thanks for the help.

      Nearing the end of the day.

      I will read it now but test it tomorrow.

      Thanks.

      I did get it to work but it was even more messy!

      Michael

      Comment


      • #4
        Re: Trouble with Javascript

        Originally posted by Michael1954 View Post
        Thanks for the help.

        Nearing the end of the day.

        I will read it now but test it tomorrow.

        Thanks.

        I did get it to work but it was even more messy!

        Michael
        Testing would probably be good. I just wrote the code in VIM & pasted it here. Will you share your working solution when you're done? Maybe there are things that could be done to make it less messy.
        Alpha Anywhere latest pre-release

        Comment


        • #5
          Re: Trouble with Javascript

          This works but I think it is held together with string.

          function Buy() {
          var flagAddRow = true;
          var existingRowCount = {dialog.Object}._getRepeatingSectionRowCount('REPEAT');
          if(existingRowCount == 1){


          var row1val = {dialog.Object}.getValue('Bagel:1')

          if(row1val == '') flagAddRow = false;
          var ele = $('{dialog.componentname}.V.R1.REPEAT');
          A5.u.element.show(ele,{show: {type: 'blind',duration: 'fast'},hide: {type: 'blind',duration: 1000}} );

          }
          if(flagAddRow){

          {dialog.Object}.addRepeatingSectionRow('REPEAT');
          }

          var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
          var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
          var Desc = {dialog.Object}.listGetValue('List1','P_Name');

          {dialog.Object}.setValue('Bagel',Bagel );
          {dialog.Object}.setValue('Price',Price );
          {dialog.Object}.setValue('Description',Desc );
          }

          function CheckForDuplicate(ContainerName,FieldName,FieldValue)
          {
          var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);

          CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);


          for (var i=1;i<={dialog.Object}._getRepeatingSectionRowCount(ContainerName);i++)

          {
          var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
          var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);
          var Qty = {dialog.object}.getValue('Qty' + ':' + row);

          Qty = +Qty + +1

          var result = (rowValue==FieldValue && CurrentRow!=row && FieldValue!='')
          var colcount = {dialog.Object}.getValue('Qty_T')


          if (i == colcount)
          {
          break;
          }
          else
          {

          }


          if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {
          // new row qty = 1
          // Add to existing Qty correct



          // leave now if the line is not a duplicate



          {dialog.object}.setValue('Qty' + ':' + row,Qty);


          {dialog.Object}.deleteRepeatingSectionRow('REPEAT',-1,true);



          }
          }

          }


          Thanks again for the help. Colcount is a summary value from the repeating section.

          Comment


          • #6
            Re: Trouble with Javascript

            Thanks Sarah it works

            One small change I needed to use Qty = +Qty + +1;
            not the more sensible Qty = Qty + 1

            Also I had hidden the repeating section until one row shows. I have made it visible for testing. Tomorrow I will tidy up.

            You really deserve a beer; I guess the time difference means you think it is too early.

            Thanks again.

            Michael

            Comment


            • #7
              Re: Trouble with Javascript

              Originally posted by Michael1954 View Post
              One small change I needed to use Qty = +Qty + +1;
              not the more sensible Qty = Qty + 1
              I've not seen + used in that fashion before. So I did a bit of research. I did not know you could convert a string to a number using +. Is your Qty a N or C type entry? Doesn't matter, really. But! I did find this series of parseInt performance tests. Super interesting!

              Glad I could help. Good luck! :)
              Alpha Anywhere latest pre-release

              Comment


              • #8
                Re: Trouble with Javascript

                Good Morning Sarah

                The beer helped. Everything appears to work.

                I had to make one small additional change.

                for (var i=0;i<=totalRows;i++)

                It was adding an extra line before this.

                Full code.


                function Buy()
                {
                var ContainerName = 'REPEAT';
                var FieldName = 'Bagel';
                var FieldValue = {dialog.object}.listGetValue('List1','Prog_Bagel');

                var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);
                CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);

                var totalRows = {dialog.Object}._getRepeatingSectionRowCount(ContainerName);
                for (var i=0;i<=totalRows;i++) {
                var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
                var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);

                if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {
                var Qty = {dialog.object}.getValue('Qty' + ':' + row);
                Qty = +Qty + +1;
                {dialog.object}.setValue('Qty' + ':' + row,Qty);

                return; //done; return early

                }

                }

                if (totalRows == 1) {
                var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,1);
                var rowValue = {dialog.object}.getValue(FieldName + ':' + row);
                if (rowValue != '') {
                //add a new row
                {dialog.object}.addRepeatingSectionRow(ContainerName);
                }
                } else {

                {dialog.object}.addRepeatingSectionRow(ContainerName);
                }

                var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
                var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
                var Desc = {dialog.Object}.listGetValue('List1','P_Name');

                {dialog.Object}.setValue('Bagel',Bagel);
                {dialog.Object}.setValue('Price',Price);
                {dialog.Object}.setValue('Description',Desc);
                }

                Comment

                Working...
                X