View Form Choice control to micmic new or edit form

Is it possible to set some of the controls like options and checkbox in view form to mimic new or edit form so it shows all the options that are not selected as well? Thank you.

Hello @ShantiBhattarai,

You can replace the Choice field with HTML control, list all elements and conditionally check the values. Please see the sample below.

The code in HTML control:

<input type="checkbox" id="Choice1" value="Choice 1" disabled> Choice1<br>
<input type="checkbox" id="Choice2" value="Choice 2" disabled> Choice1<br>
<input type="checkbox" id="Choice3" value="Choice 3" disabled> Choice1<br>

The script in JavaScript Editor:

fd.spRendered(function() {
	if (fd.field('Choice').value.includes("Choice 1")) {
		document.getElementById("Choice1").checked = true;
	}
	if (fd.field('Choice').value.includes("Choice 2")) {
		document.getElementById("Choice2").checked = true;
	}
	if (fd.field('Choice').value.includes("Choice 3")) {
		document.getElementById("Choice3").checked = true;
	}
});

Thank you this is exactly what i want.

1 Like

I'm trying to use this code in my form (view mode), checking values of a multi-choice field. It doesn't seem to want to check the boxes which are valid. Should this code still work the same? Or has something changed since this solution was posted?

Hello @Jaydius,

On a Display form, you can get field values using the code:

fd.field('Field1').displayValue;

Note, that the multiple choice field value on a display form stored as a string, not an array.

1 Like

Works perfectly! Thank you.