Likert Scale - prevent editing/updating choices after submit

By: Robert M | Asked: 02/09/2023
ForumsCategory: How-toLikert Scale - prevent editing/updating choices after submit
Robert M asked 2 years ago
How can I make a submitted Likert scale appear as read only (not hidden) when updating / editing entries from front-end? I can use the below Custom CSS on the Likert Field Class but it disables before entry is submitted - I would like to only disable during edit to an existing entry
.frm_likert_readonly {
pointer-events: none;
}
 
Attachments
2 Answers
Best Answer
Rob LeVineRob LeVine answered 2 years ago
Robert M replied 2 years ago

It does not work on Likert fields - I think because the Likert scale field does not have the attribute read only under field settings. Is there a way to add this functionality even on backend?

Rob LeVineRob LeVine replied 2 years ago

The only solution I can think of is to use jQuery to check whether you're in create or update mode and set the pointer-events value accordingly. Put the following in your form's After Fields section in the Customize HTML tab and change 478 to the id of your likert element.

jQuery(document).ready(function($){
"use strict";

var mode = $('input[name="frm_action"]').val();
if ( mode == "update") {
$("#frm_field_478_container").css("pointer-events", "none");
}
});

Rob LeVineRob LeVine replied 2 years ago

Grumble. That code should be wrapped in script tags when you put it in the After Fields section

Robert M answered 2 years ago

@Rob LeVine , your first suggestion does actually works but in an weird way. I realized that each row in a Likert scale is treated as an unique field with its own field ID. So I have to add ID's of all questions in my Likert scale - about 70 of them!!! Here's  how my would look :) 

add_filter('frm_setup_edit_fields_vars', 'frm_set_read_only', 20, 3);
function frm_set_read_only($values, $field, $entry_id){
	// If on the back-end, keep fields editable
	if ( FrmAppHelper::is_admin() ) {
	  return $values;
  	}

	// If on front-end, make specific fields read-only
	if ( in_array( $field->id, array( 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75 ) ) ) { 
	   $values['read_only'] = 1;
	}	
	return $values;
}
Victor Font replied 2 years ago

Here's a tip about another way to do this where you can build your field list dynamically so you don't have to worry about whether you need to change custom code when you add or delete likert fields. All you have to do is use:

if ( $field->type == "likert" )

You can further filter the list by form:

if ( $field->type == "likert" && $field->form_id = "99" ) // change 99 to your form's id

The first example applies to all likert fields on all of your forms. The second example is for a specific form.

Robert M replied 2 years ago

Thank for this tip, though I want a selection and not all of the Likert questions as read only on edit. Maybe what would work in my case is maybe filter by Field Key.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right