Versions Compared

Key

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

...

Now replace the hard coded list of coffee shops with a rule that invokes an http.get. This must return an X-JSON header which contains a JSON object. The object is evaluated and assigned to the variable x. In this case the JSON object contains an options field of type array. See the section on dynamic content for more details.

Code Block
languagejavascript
var x;
if (search.clicked) 
{ 
    eval('x=' + http.get('http://<webhost>/getCoffeeShopList'));  
    coffeeShopList.options = x.options; 
}
Tip

Triggers do not work in repeating items.

...

This rule executes when the user enters a value into the Username text field. It uses the built-in isUniqueUserId() method that returns false if the user already exists. If the user already exists this rule then sets the value of a message control, makes that message control visible on the form and sets the Username valid property to false so that Username field displays as invalid to guide the user to make a correction. See the section on dynamic content for more details.

Code Block
languagejavascript
if (U.value.length > 0) {  
    if (frevvo.isUniqueUserId(user.value, tenant.value) === false) { 
        M.value = 'User: ' + U.value + ' already exists'; 
        M.visible = true; 
        U.valid = false; 
    } else { 
        M.visible = false; 
    } 
}

Digital Signature

This form uses a rule to pass a username and password to a LDAP Active Directory authentication service. If authentication fails the form makes an error message control visible. If authentication succeeds the form disables the username form field and replaces the password field with a date field set to the current date. The form contains a trigger control named sign, username and password fields named u and p respectively, a date field named d and a message field named m.

Code Block
languagejavascript
/*member auth */
var x;
  
if (sign.clicked) { 
    // passwords may contain characters that need url encoding 
    var p_encode = encodeURIComponent(p.value);

    eval('x=' + http.get('http://<webhost><myhost>/authServices/signForm?username=' +  
                          u.value + '&password=' + p_encode));

    if (x.auth) { 
        var dt = new Date(); 
        var day = dt.getDate(); 
        var month = dt.getMonth() + 1; 
        var year = dt.getFullYear(); 
        d.value = month + '-' + day + '-' + year;

        d.visible = true; 
        u.enabled = false; 
        p.visible = false; 
        sign.visible = false; 
        m.visible = false; 
    } else { 
    m.visible = true; 
    } 
}

The authService is an example HTTP servlet that returns a JSON response.

...

This form initializes the hospital discharge date using a rule, and when the user enters the admission date a 2nd rule calculates the number of days the patient stayed in the hospital.

Code Block
languagejavascript
/ Calculate Hospital Stay Duration 
if (A.value !== '' && D.value !== '') { {
    var da = A.value.split('-'); 
    var Ams = new Date(da[02],da[0]-1],da[21]); 
    da = D.value.split('-'); 
    var Dms = new Date(da[02],da[0]-1],da[21]);
  var
oneDay = 24*60*60*1000;    if (Ams > Dms) { 
        Days.value = 'Discharge date must be after Admission Date'; 
    } else { var diffDays 
        Days.value = Math.round(Math.abs((Ams.getTime()(Dms - Dms.getTime())/(oneDay))); Days.value = diffDays Ams) / (1000*60*60*24) + ' days'; 
    } 
}

Today's Date and Time

Use 's built-in date and time methods to set your date, time, and date/time controls to the current date and time in the user's local timezone.

...

Code Block
var today = new Date(); 
var bd = DOB.value.split('-'); 
var bd_date = new Date(bd[0],bd[1]-1,bd[2]);

if (bd_date.getTime() > today.getTime()) { 
    MyMsg.value = 'Birth Date must be earlier than today!!!!';   
    DOB.valid = false; 
} else { 
    MyMsg.value = 'This is a good Birth Date: ' + DOB.value; 
DOB.valid = true; 
}

Date no more then 14 days from Today

...