Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When the form is submitted we've configured  to send an email with the form PDF. We only want the Details section to appear on the PDF when the user selects 'Yes'. So we uncheck the printable property on the section control. This property will apply to the section and all controls inside the section. So we do not have to uncheck printable on the inner controls. Then we add this business rule. When the section is visible we also set it to be printable. When the section is hidden we also set it to be not printable.

Code Block
languagejavascript
if (DescribeInDetail.value === 'Yes') { 
    Details.visible = true; 
    Details.printable = true; 
} else { 
    Details.visible = false; 
    Details.printable = false; 
} 

...

You have a form with multiple tabs. The main tab contains the form and the other tabs contain reference information users may need when completing the form. You only want the submit and cancel buttons visible when the user is in the main tab. This rule hides the submit and cancel buttons when the reference tabs are selected. The control name of the main tab is MainTab.

Code Block
languagejavascript
if (!(MainTab.selected)) {
    Submit.visible = false;
    Cancel.visible = false;
} else {
   Submit.visible = true;
   Cancel.visible = true;
}

...

You have a form with two controls and you have assigned them Names B and Q respectively. B is a checkbox with a single option - Yes. . If checked the user is a smoker and you wish to ask an additional question in Q. The rule would be written as

Code Block
languagejavascript
if (B[0].value === 'Yes') {
    Q.enabled = true; 
} else {
 Q.enabled = false; 
} 

...

The rule would be written as:

Code Block
languagejavascript
for (var i = 0; i < S.value.length; i++) { 
  if (Q[i].value > 0) {
    S[i].value = Q[i].value * P[i].value; 
  } else { 
    S[i].value = 0; 
  } 
}   

...

Consider the same form as the example above. Let's say you have a control named Total with Name T. You want to set the value of Total to be the total invoice price, which is the sum of all the computed subtotals above. This rule would be written as:

Code Block
languagejavascript
var tot = 0; 
for (var i = 0; i < S.value.length; i++) {
  tot = tot + S[i].value; 
} 
T.value = tot; 

This rule will fire whenever a subtotal is updated, for example, when it is updated via the rule above. It will add the values of all the subtotals to arrive at an invoice total. Note that you must use a temporary variable to compute the total. If you write the rule as:

Code Block
languagejavascript
T.value = 0; 
for (var i = 0; i < S.value.length; i++) {
  T.value = T.value + S[i].value; 
} 

...

Tip

Note that this rule is working with controls inside a repeat control. To handle the case of a item being deleted from the repeat you need the following addition assuming that the repeat control is named ExpenseRepeat. Table controls are repeats with a different layout. Thus the same applies to the table controls. If your table is named Expense then the repeat is automatically named ExpenseRepeat. In general the table repeat is named <TableName>Repeat.

Code Block
languagejavascript
if (ExpenseRepeat.itemRemoved) {var x;} 

...

In html there is no way to set a maxLength on a textarea control. This is why the textarea control does not have a maxlength property like the text control does. It is possible to do this via a business rule. This example form has a textarea control named 'Desc' where the user can enter up to a 500 character description. On this control we also set the ErrorMsg property to the string 'You must limit your description to 500 characters'. This message is automatically displayed when the description control is set to invalid by the following business rule.

Code Block
languagejavascript
if (Desc.value.length > 500) {
  Desc.valid = false; 
} else {
  Desc.valid = true; 
} 

...

Our example has a textarea control named Description and a hidden control named DF. The user types into the visible control named Description and a business rules converts the newline characters \n into html breaks.

Code Block
languagejavascript
var x = Description.value; 
x = x.replace(/\\r/g,"");
x = x.replace(/\\n/g,"<br/>");
DF.value = x; 

...

The 1st rule "Load Products" populates both the visible and hidden dropdowns with options from a database.

 

Code Block
languagejavascript
/*member description productId resultSet */
var x;
 
if (form.load) { 
eval('x=' + http.get('http://localhost:8082/database/products'));   
var opts1 = []; 
var opts2 = [];   
 
for (var i=0; i < x.resultSet.length; i++) { 
  if (x.resultSet[i]) { 
    opts1[i] = x.resultSet[i].description; 
    opts2[i] = x.resultSet[i].productId; 
  } 
}    
 
Products.options = opts1; 
PID.options = opts2; 
Products.value = opts1[0]; // default to 1st product option 
PID.value = opts2[0]; 
}

...

The 2nd rule Select Product ID keeps the hidden PID dropdown syncronized with the visible Products dropdown.

Code Block
languagejavascript
if (Products.value.length > 0) 
{ 
    var i; 
    for (var x in Products.options) {
        if (Products.value === Products.options[x]) 
            i = Products.options.indexOf(Products.options[x]); 
}

PID.value = PID.options[i] + ''; 
}

...

Here is another rule that dynamically populates both the product choices and product ID dropdowns. This rule calls a REST Service which returns an object rather than the resultset returned by the database connector as shown above. See the section on dynamic content for more details.

Code Block
languagejavascript
/*member ids products */
var x;
 
if (S.value.length > 0) {
    eval('x=' + http.get('http://<webhosts>/products/?category=' + S.value)); 
    P.options = x.products; ID.options = x.ids;
}

...