Results 1 to 4 of 4

Thread: Value of field doesn't save

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    7

    Value of field doesn't save

    I have a field on a page, I set it's value with a Lianja.get("Scrap_Bins_Used.section3.BinTareWeight ").value = BinFound the correct value displays in the field box but if I save the record it revert back to the previous value in the field. If I type in the field the value that was placed there from the above statement it saves.

    How do I get Lianja to save the value without physically typing that value in the field?

    Thanks
    Jon

  2. #2
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    1,955
    Hi Jon,

    In 5.2, the action of saving a new value to a field in a table used as a controlsource involves getting the section cursor, using the section's getCursor() method. The data then gets moved to the cursor using the cursor object's setData() method. The data then gets saved to the backend using the Update method of the cursor object. A call to the section's Refresh method will then get the data from the backend data and show the change in the section. Note that for testing purposes, the code you have will display the change you made, which can be handy for initial testing. If you were going beyond that to actually save the data, you would follow the steps listed above, substituting them for that one line of code.

    It's easy enough to write a function (in JavaScript or VFP) to handle of all of what you thought should work. It would need to have passed a) the section path (page.section), b) the control id, and c) the new value for that control.

    That said, I've heard a rumor from an ordinarily good source that changes in 5.3 will make writing that function unnecessary, or at least much simpler. Stay tuned.

    Hank
    Last edited by HankFay; 2020-04-26 at 17:14.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    7
    So how exactly is that structured?

    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'changed' event
    function Scrap_Bins_Used_section3_field12_changed()
    {
    	// insert your code here
    	var BinFound = keylookup("ScrapBinWeights","BINNUMBER",Lianja.get("Scrap_Bins_Used.section3.field12").value,"?BinTareWeight","0");
    	if (BinFound == 0){
    		messageBox("Bad Bin # -- try again.");
    	} else {
    		Lianja.get("Scrap_Bins_Used.section3.BinTareWeight").value = BinFound;
    		Lianja.getCursor('scrapweights') ;
    
    	}
    	
    }
    I'm used to VFP Thisform.field1.value = myvalue. and thats all there is to it

    Whats the syntax for doing what you recommend?


    Quote Originally Posted by HankFay View Post
    Hi Jon,

    In 5.2, the action of saving a new value to a field in a table used as a controlsource involves getting the section cursor, using the section's getCursor() method. The data then gets moved to the cursor using the cursor object's setData() method. The data then gets saved to the backend using the Update method of the cursor object. A call to the section's Refresh method will then get the data from the backend data and show the change in the section. Note that for testing purposes, the code you have will display the change you made, which can be handy for initial testing. If you were going beyond that to actually save the data, you would follow the steps listed above, substituting them for that one line of code.

    It's easy enough to write a function (in JavaScript or VFP) to handle of all of what you thought should work. It would need to have passed a) the section path (page.section), b) the control id, and c) the new value for that control.

    That said, I've heard a rumor from an ordinarily good source that changes in 5.3 will make writing that function unnecessary, or at least much simpler. Stay tuned.

    Hank

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,778
    Hi Jon,

    Coming in Lianja 5.3...


    • When JavaScript delegates are called you can now reference the UI element for the delegate using This (capital T), thisElement or thiselement. This reduces typing.


    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'changed' event
    function Scrap_Bins_Used_section3_field12_changed()
    {
        var BinFound = keylookup("ScrapBinWeights","BINNUMBER",This.value,"?BinTareWeight","0");
        if (BinFound == 0) messageBox("Bad Bin # -- try again.");
        else This.value = BinFound;
    }
    Note that you don't need to hand code validation like that you can just specify it and a message to be displayed if validation failed in the UI attributes for the field.

    This can also be specified in the Data Dictionary or ColumnMetaData so that it is applied in all forms/gridcolumns that are bound to that column.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

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
  •  
Journey into the Cloud
Join us