alter just entered field

I need to adjust a just-entered field on the edit page, like the example below

 

               var comp = .... ;

                var amount = this.get("FinAmount");

                if (!amount) {

                    amount = 0;

                }

                if (comp === "x") {

                    this.set("FinAmount", -amount);

                }

FinAmount is a page editable field. The new value is shown on the page, but it is not saved when the save button is pressed.

The code works fine with read-only fields.

 

Please help 

Like 0

Like

9 comments

Dear Ricardo, 

 

Here is the working example of the code that changes the value of the column UsrTest to the -value when the column value is changed (works for non read-only fields as well). Please debug your code if the same code works differently for you: 

		attributes: {
			"UsrTest": {
				"dependencies": [
				  {
					"columns": [ "UsrTest" ],
					"methodName": "setUsrTest"
				  }
				]
			}, 
			"UsrTestChanged": {
					"dataValueType": this.Terrasoft.DataValueType.BOOL,
					"type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				"value": 0
		}
}

 

			setUsrTest: function(){
				if (this.get("UsrTestChanged") === 0){
					this.set("UsrTestChanged", 1); 
					var amount = this.get("UsrTest");
					this.set("UsrTest", -amount);
					//this.save(); 
				}
				else {
					this.set("UsrTestChanged", 0); 
				}
			},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "insert",
				"name": "INTEGERa10da2ec-524f-4a7d-9219-7bb6acbefd2c",
				"values": {
					"layout": {
						"colSpan": 24,
						"rowSpan": 1,
						"column": 0,
						"row": 8,
						"layoutName": "ProfileContainer"
					},
					"bindTo": "UsrTest",
					"enabled": true
				},
				"parentName": "ProfileContainer",
				"propertyName": "items",
				"index": 8
			},

 

Best regards, 

Dennis 

Dennis Hudson,

Thanks for your reply.

I have tried your code, but got the same results.

The sign of the field is changed on the screen, but it is not saved...

 

My code:

                    "FinAmount": {

                        dataValueType: Terrasoft.DataValueType.FLOAT,

                        dependencies: [

                            {

                                columns: ["FinAmount"],

                                methodName: "adjustAmount"

                            }

                        ]

                    },

                    "FinAmountChanged": {

                        "dataValueType": this.Terrasoft.DataValueType.BOOL,

                        "type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,

                    "value": 0

                    },

 

...

 

            // Handler method that calculates the sign of the [FinAmount] column.

            adjustAmount: function() {

                    var crDb = this.get("FinCrDb");

                    if (crDb === "Db") {

                        this.set("FinAmountChanged", 1);

                        var amount = this.get("FinAmount");

                        this.set("FinAmount", -Math.abs(amount));

                        this.set("FinAmountChanged", 0); 

                    } 

            }

...

 

            {

                "operation": "insert",

                "name": "FLOATe30ea95d-a165-4b34-ac4b-7e9c33102483",

                "values": {

                    "layout": {

                        "colSpan": 8,

                        "rowSpan": 1,

                        "column": 0,

                        "row": 0,

                        "layoutName": "Header"

                    },

                    "bindTo": "FinAmount",

                    "labelConfig": {

                        "caption": {

                            "bindTo": "Resources.Strings.FLOATe30ea95da1654b34ac4b7e9c33102483LabelCaption"

                        }

                    },

                    "enabled": true

                },

                "parentName": "Header",

                "propertyName": "items",

                "index": 3

            },

 

Dear Ricardo Bigio,

 

You can save the page with the method this.save()

 

Best regards, 

Dennis 

Dennis Hudson,

I have tried this.save() too (although it is nor appropriate for us , as the page is saved regardless of the user has decided to save). But the result is  the same. The page is saved without the change in the field.

Ricardo Bigio,

 

You can set the value of the field directly in db using UpdateQuery. Please see the example in the article below: 

https://academy.creatio.com/documents/technic-sdk/7-16/handling-selection-several-records-examples

 

Best regards, 

Dennis 

Dennis Hudson,

Thanks again.

I need a solution to be done in the edit page, automatically, as the user enters the field values, according to the dependencies among them.

UpdateQuery will not be suitable in this case.

Any other suggestion ?

Ricardo Bigio,

 

UpdateQuery can be done on the edit page as well and will automatically update the value of the column in db (please see example in the academy page I've sent earlier). Could you please specify why it wouldn't work in your case? 

 

Best regards, 

Dennis 

Dennis Hudson,

Is there a solution in which the value is saved ONLY in the page (not in db) ? Of course it will be saved in the db if the user hits "SAVE" afterwards).

Ricardo Bigio,

 

In case you use a method such as:

 

onEntityInitialized: function(){
				this.callParent(arguments);
				this.set("UsrInteger2",2);
			}

the value of 2 won't be saved for UsrInteger2 column in the database (until the "Save" button is not clicked and the database value is ignored in the UI). Each time the "Save" button is clicked an UPDATE query is executed and there is no way to override the "Save" button functionality.

 

Best regards,

Oscar

Show all comments