Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-24125

Use Array.push pattern to define toolbar children to prevent invalid commas

    Details

      Description

      When we define a new A.Toolbar with conditional inline children such as

      var toolbar = new A.Toolbar(
          children: [
              <c:if test="something">
                  one,
              </c:if>
              <c:if test="something-else">
                  two
              </c:if>
          ]
      );
      

      It's possible that the inline javascript array will result in a syntax error, because if the first child's condition is true and the second child's condition is false, then we get:

      var toolbar = new A.Toolbar(
          children: [
                  one,
          ]
      );
      

      which is invalid Javascript. For this reason we should define an array of children and use the push method instead. Example:

      var toolbarChildren = [];
      
      <c:if test="something">
          toolbarChildren.push(
              one
          );
      </c:if>
      <c:if test="something-else">
          toolbarChildren.push(
              two
          );
      </c:if>
      
      var toolbar = new A.Toolbar(
          children: toolbarChildren
      );
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              support-lep@liferay.com SE Support
              Reporter:
              jonathan.potter Jonathan Potter (Inactive)
              Participants of an Issue:
              Recent user:
              Esther Sanz
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                9 years, 21 weeks, 2 days ago

                  Packages

                  Version Package
                  6.1.1 CE GA2
                  6.1.20 EE GA2
                  6.2.0 CE M2