Alpha DevCon 2018
Results 1 to 2 of 2

Thread: How to update the value of a dependent field in a Formview?

  1. #1
    Member
    Real Name
    Doug Evenhouse
    Join Date
    Apr 2009
    Posts
    47

    Default How to update the value of a dependent field in a Formview?

    Hi,

    Are there any events on a Formview field (onBlur for example) to which I can attach javascript that can update other fields in the form? Say I want to update a "Total" field after the user inputs a "Price" value. How would I go about doing that? I think I could use an Editor's "Get value from editor" property to update other fields in the form but if I'm using a generic Editor I would have to rely on custom settings and check for static values to know which field is currently being edited and what to do with the value being committed. That's not optimal.

    Is the beta Formview outfitted for this kind of thing at this point? Or maybe I'm missing something?

    Thanks.

    Doug

  2. #2
    Alpha Software Employee Beta Spark's Avatar
    Real Name
    Sarah Mitchell
    Join Date
    Jul 2015
    Posts
    399

    Default Re: How to update the value of a dependent field in a Formview?

    Quote Originally Posted by dougeven View Post
    Hi,

    Are there any events on a Formview field (onBlur for example) to which I can attach javascript that can update other fields in the form? Say I want to update a "Total" field after the user inputs a "Price" value. How would I go about doing that? I think I could use an Editor's "Get value from editor" property to update other fields in the form but if I'm using a generic Editor I would have to rely on custom settings and check for static values to know which field is currently being edited and what to do with the value being committed. That's not optimal.

    Is the beta Formview outfitted for this kind of thing at this point? Or maybe I'm missing something?

    Thanks.

    Doug
    Hi Doug!

    There is a function in the {dialog.object} that can be used to set values in the FormView called "formViewUpdate". This function takes 3 parameters, the ID for the FormView control, an array of columns (aka, fields) to update, and a matching array of values for those fields.

    In the Editor Set, there is a javascript method available called "Commit javascript". You can add javascript to this event, which happens when any of the editors in the editor set are committed. There are two variables available when working with this event: 'value' and 'settings'. 'value' is the value returned by the "Get value from editor" javascript function for an editor. 'settings' is a JSON object containing information about the FormView, editor, and more. If you want to see what's available in 'settings', add this line of code to the Commit javascript:

    Code:
    alert(JSON.stringify(settings));
    SO, with that background knowledge, I can provide you with an example. Below is code I created that updates a TOTAL field with the total price for a line item. There are two fields the total is calculated from: QUANTITY and PRICE. I put this code in the Commit javascript (Note: this isn't the smartest code. For example, it will execute every time the Commit javascript method is called, even if QUANTITY and PRICE have not changed.):
    Code:
    // get what column is being modified
    var col = settings["*a5column"]; 
    
    // Get the quantity. If we're editing "QUANTITY", then we use 'value'. Otherwise, get it from settings:
    var q = $u.s.toNum(col == "QUANTITY"? value : settings["data"]["QUANTITY"]);
    
    // Get the price. If we're editing "PRICE", then we use 'value'. Otherwise, get it from settings:
    var p = $u.s.toNum(col == "PRICE" ? value : settings["data"]["PRICE"]);
    
    var totalField = 'TOTAL';
    var totalValue = q*p;
    
    var formViewToUpdate = 'FORMVIEW_1';
    var fieldsToUpdate = [totalField];
    var valuesForFields = [totalValue];
    
    {dialog.object}.formViewUpdate(formViewToUpdate, fieldsToUpdate, valuesForFields);
    Hope this helps!
    Sarah Mitchell

    Looking for answers? Try our documentation.
    If you can't find something, let us know!

Similar Threads

  1. Field validation javascript in Formview not firing if value is null/undefined
    By dougeven in forum Tablet-Optimized Form Capabilities Beta
    Replies: 6
    Last Post: 10-09-2015, 03:08 PM
  2. How to format date field in a formview
    By dougeven in forum Tablet-Optimized Form Capabilities Beta
    Replies: 2
    Last Post: 09-25-2015, 05:39 PM
  3. Row Expander - making it dependent on a field in another table.
    By Atta in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 09-19-2011, 12:18 PM
  4. Populate dependent values
    By RedSun8 in forum Application Server Version 9 - Web/Browser Applications
    Replies: 0
    Last Post: 07-03-2009, 03:27 AM
  5. Replies: 5
    Last Post: 01-10-2006, 10:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •