Custom form elements with all options already pre-set for the editor (and probably not changeable)


Hi Team,

I want to know if it is possible to do something like below:

I want to create some cutom form elements which will be fixed and important for my form to execute a particular functionality. So instead of user to create them and then put the correct configuration they just add the custom form element and no need to configure anyting for it.

For example: Instead of textbox form element i create a textfield where i have to put the field name to be FirstName, and make it a required, i would create a First Name Field in there, and all the options would be already pre-set for the editor (and probably not changeable) and for rest of the fields they can use the existing textbox form element.

Is it possible to achieve this as form elements of form container.

Jul 15, 2020 16:54

Override the method SetDefaultValues when you create the custom element. In that method you can set default value for any property of the element.

Jul 17, 2020 6:25

Thank you, i was able to do that but is there a way to not let user change the values which i set through SetDefaultValues. 

Jul 17, 2020 6:33

You can try to add the attribute [Editable(false)] to the property which you want to disallow editor change.

Jul 17, 2020 6:42
Swati - Jul 17, 2020 15:27
But i want the base properties which i set through SetDefaultValues not to be changed by user.

For eg: I have only SetDefaultValues method in my customBlock which inherits from TextBoxElementBlock, now the block is set to required but i dont want user to change it through cms.

public override void SetDefaultValues(ContentType contentType)
Label = "Last Name";
PlaceHolder = "Doe";
this.Validators = typeof(RequiredValidator).FullName;
Dac Thach Nguyen - Jul 20, 2020 3:40
You need to override the base property and and the attribute [Editable(false)]
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.