Field requirement via code

Greetings. 

I have a need to give users the ability to decide, which fields should be required for a particular page. I had some sort of the solution in my head. It makes an request and returns with a list of fields that need to be required for this particular page. The problem I am facing is making fields required via JS code (not in Diff section but in the code section, like "onEntityInitialized"). Looking forward to seeing the possible ways to solve this problem.

Like 0

Like

1 comments

Hello,

In order to make a field required based on the condition you need to bind it to an attribute, here is an example of how to do it:

1) Create a new boolean attribute

attributes: {
			"IsValueRequired": {
				"dataValueType": Terrasoft.DataValueType.BOOLEAN,
				"value": false
			}
		},

2) Bind this attribute to an "IsRequired" parameter in the field diff:

"values": {
					"isRequired": {"bindTo": "IsValueRequired"},
					"layout": {

3) Set the value to this attribute in the onEntityInitialized method:

methods: {
			onEntityInitialized: function() {
				this.callParent(arguments);
				this.setIsValueRequired();
			},
			setIsValueRequired: function() {
				if (YOUR CONDITION) {
					this.set("IsValueRequired", true);
				}
				else this.set("IsValueRequired", false);
			}
		},

 

Show all comments