Make several fields disabled and others enabled due some condition

Good morning,

I need to make some fields Editable and some not (enabled or not) due some condition. But it doesn't works.

What I did?

1.- on the diff block I replace on every field block:

        replace "enabled": true by  "enabled": { "bindTo": "isUsrGiroEnabled" }, for example:

{
	"operation": "insert",
	"name": "STRINGe657cf87-7461-450e-beb8-8429d591a8ea",
	"values": {
		"layout": {
			"colSpan": 12,
			"rowSpan": 1,
			"column": 0,
			"row": 0,
			"layoutName": "ProductsTabGridLayout30090ad7"
		},
		"bindTo": "UsrGiro", 
		"enabled": { "bindTo": "isUsrGiroEnabled" } // Replaced "enabled": true
	},
	"parentName": "ProductsTabGridLayout30090ad7",
	"propertyName": "items",
	"index": 0
},

2.- Create an onEntityInitialized method to call when the form loads the method evaluate the fileds must be filled or not. (Enabled)

onEntityInitialized: function() { //callback, scope) {
 
	this.callParent(arguments);
 
	this.isCampoEnabled();
},

The method that evaluate if a field is Editable or not

isCampoEnabled: function() {
	// Evalua Tipo de Negocio
	var tipoNegocio = this.get( "UsrLineaNeg" ).displayValue;
	var tipoNegocioCCV = ( tipoNegocio.substring( 0, 2 ) === "CCV" ) ? true : false;
	var tipoNegocioOficinas = ( tipoNegocio.substring( 0, 2 ) === "Ofi" ) ? true : false;
	var tipoNegocioIndustrial = ( tipoNegocio.substring( 0, 2 ) === "Ind" ) ? true : false;
	var tipoNegocioMALL = ( tipoNegocio.substring( 0, 2 ) === "Mal" ) ? true : false;
 
	// Campos que SIEMPRE SON HABILITADOS				
	this.set( "IsUsrRubroEnabled", true );
	this.set( "IsUsrGiroEnabled", true );
 
	if ( tipoNegocioCCV ) {
		// Deshabilida sólo los de CCV
		this.set( "IsUsrRepLegal1Enabled", false );
 
       // the same to another fields
    }
}

What's missing?, it doesn't works. ALL fields set NOT Editable.

Thankjs in advance

Like 0

Like

3 comments

Dear Julio,

Please add a virtual attribute "IsUsrGiroEnabled", which you are setting to true in the "isCampoEnabled" function. The rest of the functionality and approach are correct. Though, after adding the attribute, I would suggest to leave only this.set( "IsUsrGiroEnabled", true ); in the "isCampoEnabled" function, so to check that functionality is working and exclude the possible error in the rest of the function body. On the other hand, you can debug the code in the runtime.

Here is an example of virtual Boolean attribute:

"NumberDoesNotExist": {
        "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
        "dataValueType": Terrasoft.DataValueType.BOOLEAN,
        "value": false
    }

Regards,

Anastasia

Thanks Anastasia, could be I doing someting wrong, because it doesn't works.

1.- The diff definition

{
	"operation": "insert",
	"name": "STRING439d943b-0a59-4e30-bdf6-e36c310ba8f1",
	"values": {
		"layout": {
			"colSpan": 12,
			"rowSpan": 1,
			"column": 0,
			"row": 1,
			"layoutName": "ProductsTabGridLayout30090ad7"
		},
		"bindTo": "UsrNomFantasia",
		"enabled": {
			"bindTo": "isUsrNomFantasiaEnabled"
		}
	},
	"parentName": "ProductsTabGridLayout30090ad7",
	"propertyName": "items",
	"index": 2
},

2.-Attribute

"IsUsrNomFantasiaEnabled": {
	"type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
	"dataValueType": Terrasoft.DataValueType.BOOLEAN,
	"value": true
}

3.- The code

onEntityInitialized: function() {
	this.callParent(arguments);
 
	this.isCampoEnabled();
},
 
isCampoEnabled: function() {
	// Evalua Tipo de Negocio
	this.set( "IsUsrNomFantasiaEnabled", true );
}

After all of these the field is disabled, what I'm doing wrong?

 

Thanks in advance

Dear Julio,

Unfortunately, it is impossible to determine the exact cause as of now. Could you, please direct this issue on to the support team via email so we could investigate more closely.

Thank you,

Anastasia

Show all comments