Child pages
  • Creating form with star based ratings table view

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

With ConfiForms you have endless possibilities on how you can create your forms or how to present the data captured with you forms. This page touches the basics - Multiple ways to show your form data in Confluence with ConfiForms

Here we wanted to show you how you can extend this and do something cool by showing the "stars" instead of boring ratings values for your data


Consider having a form like this


Image Added

Just one field to capture and that is "rating" field. We use Radio Group as it's type and it has the following values

Image Added


So, we put a standard TableView on the page to show the ratings value. And instead of showing something like this

Image Added


We want this


Image Added



Here is an example of a form with custom field of rating points replaced by star image.

So, we have a form with one radio button field which values are replaced with star image.

Image Removed

Raw strorage format of an example, which demonstrates this form with script


We will need some help from JavaScript to replace the ratings values with stars

Here is how this can be done

Code Block
<script type="text/javascript">
function getValFromClass(cfClassName) {
	var ind = cfClassName.indexOf("-",1);
	if (ind > 0) {
		cfValue = cfClassName.slice(ind+1, cfClassName.length);
	}
	return cfValue;
}

function getStarHtml(cfValue) {
	var starHtml = "";
	for (var ind = 0; ind < cfValue; ind++) {
		starHtml = starHtml + AJS.$("#mystardiv").html();
	}
	return starHtml;
}

function setStarHtml(cfClassName) {
	if (typeof cfClassName !== typeof undefined && cfClassName !== false) {
		cfValue = getValFromClass(cfClassName);
		var star = "";
		star = getStarHtml(cfValue);
		selector = "span[class='" + cfClassName + "']";
		AJS.$(selector).html(star);
	}
}

function setRatingImg(cfName) {
	var spanSelector = "span[cf-field='" + cfName + "']";
	AJS.$(spanSelector).each(function(){
		setStarHtml(AJS.$(this).attr('class'))
  	});	
}

AJS.toInit(function() {
	// replace the "rating" field
  	setRatingImg('rating');
});
</script>

// hidden place for the star image
<div id="mystardiv" style="display:none">
<img id="mystar" alt="1 point" title="1 point" style="" data-choice="1" width="20px" src="data:image/svg+xml;utf8;base64,PHN2Zw0KICAgIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIg0KICAgIHhtbG5zOnJkZj0ia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iDQogICAgICAgICAgZD0ibTI4OS44IDU3NC41MyAxMS4yNjEtNjYuNTQxIDQ4Ljc1Ny0xNS42Nzl6Ig0KICAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmQ0MmEiDQogICAgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCINCiAgICAgIC8+DQogICAgPC9nDQogICAgPg0KICA8L2cNCiAgPg0KICA8bWV0YWRhdGENCiAgICA+DQogICAgPHJkZjpSREYNCiAgICAgID4NCiAgICAgIDxjYzpXb3JrDQogICAgICAgID4NCiAgICAgICAgPGRjOmZvcm1hdA0KICAgICAgICAgID5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQNCiAgICAgICAgPg0KICAgICAgICA8ZGM6dHlwZQ0KICAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSINCiAgICAgICAgLz4NCiAgICAgICAgPGNjOmxpY2Vuc2UNCiAgICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvcHVibGljZG9tYWluLyINCiAgICAgICAgLz4NCiAgICAgICAgPGRjOnB1Ymxpc2hlcg0KICAgICAgICAgID4NCiAgICAgICAgICA8Y2M6QWdlbnQNCiAgICAgICAgICAgICAgcmRmOmFib3V0PSJodHRwOi8vb3BlbmNsaXBhcnQub3JnLyINCiAgICAgICAgICAgID4NCiAgICAgICAgICAgIDxkYzp0aXRsZQ0KICAgICAgICAgICAgICA+T3BlbmNsaXBhcnQ8L2RjOnRpdGxlDQogICAgICAgICAgICA+DQogICAgICAgICAgPC9jYzpBZ2VudA0KICAgICAgICAgID4NCiAgICAgICAgPC9kYzpwdWJsaXNoZXINCiAgICAgICAgPg0KICAgICAgICA8ZGM6dGl0bGUNCiAgICAgICAgICA+U3RhcjwvZGM6dGl0bGUNCiAgICAgICAgPg0KICAgICAgICA8ZGM6ZGF0ZQ0KICAgICAgICAgID4yMDEwLTExLTEzVDIwOjE3OjU1PC9kYzpkYXRlDQogICAgICAgID4NCiAgICAgICAgPGRjOmRlc2NyaXB0aW9uDQogICAgICAgICAgPkEgc3RhciB3aXRoIHNpbXBsZSBzaGFkb3dpbmc8L2RjOmRlc2NyaXB0aW9uDQogICAgICAgID4NCiAgICAgICAgPGRjOnNvdXJjZQ0KICAgICAgICAgID5odHRwczovL29wZW5jbGlwYXJ0Lm9yZy9kZXRhaWwvOTU0MzEvc3Rhci1ieS1hcnRva2VtPC9kYzpzb3VyY2UNCiAgICAgICAgPg0KICAgICAgICA8ZGM6Y3JlYXRvcg0KICAgICAgICAgID4NCiAgICAgICAgICA8Y2M6QWdlbnQNCiAgICAgICAgICAgID4NCiAgICAgICAgICAgIDxkYzp0aXRsZQ0KICAgICAgICAgICAgICA+YXJ0b2tlbTwvZGM6dGl0bGUNCiAgICAgICAgICAgID4NCiAgICAgICAgICA8L2NjOkFnZW50DQogICAgICAgICAgPg0KICAgICAgICA8L2RjOmNyZWF0b3INCiAgICAgICAgPg0KICAgICAgICA8ZGM6c3ViamVjdA0KICAgICAgICAgID4NCiAgICAgICAgICA8cmRmOkJhZw0KICAgICAgICAgICAgPg0KICAgICAgICAgICAgPHJkZjpsaQ0KICAgICAgICAgICAgICA+c3RhcjwvcmRmOmxpDQogICAgICAgICAgICA+DQogICAgICAgICAgPC9yZGY6QmFnDQogICAgICAgICAgPg0KICAgICAgICA8L2RjOnN1YmplY3QNCiAgICAgICAgPg0KICAgICAgPC9jYzpXb3JrDQogICAgICA+DQogICAgICA8Y2M6TGljZW5zZQ0KICAgICAgICAgIHJkZjphYm91dD0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5zZXMvcHVibGljZG9tYWluLyINCiAgICAgICAgPg0KICAgICAgICA8Y2M6cGVybWl0cw0KICAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyNSZXByb2R1Y3Rpb24iDQogICAgICAgIC8+DQogICAgICAgIDxjYzpwZXJtaXRzDQogICAgICAgICAgICByZGY6cmVzb3VyY2U9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zI0Rpc3RyaWJ1dGlvbiINCiAgICAgICAgLz4NCiAgICAgICAgPGNjOnBlcm1pdHMNCiAgICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjRGVyaXZhdGl2ZVdvcmtzIg0KICAgICAgICAvPg0KICAgICAgPC9jYzpMaWNlbnNlDQogICAgICA+DQogICAgPC9yZGY6UkRGDQogICAgPg0KICA8L21ldGFkYXRhDQogID4NCjwvc3ZnDQo+DQo=">
</div>

...