You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

How to call functionality from the autoload.js file in the logic.js file of a widget

Received Response
10
Views
4
Comments
edited Jul 10, 2018 7:06PM in Customer Portal 4 comments

Content

Hi,

From the code block below, you can see I have quite a length function called validateForm. This sits across several widgets. If I have to make a change, I have to do it in several places. If it's in 100 widgets.... 100 changes

My question is whether I can utilise the autoload.js file to contain this function and call it from logic.js? How would I go about ding this if so?

Code Snippet

             RightNow.namespace('Custom.Widgets.planning_programming.Submit');
Custom.Widgets.planning_programming.Submit = RightNow.Widgets.FormSubmit.extend({
    overrides: {
		constructor: function(){
			this.parent();
			RightNow.Event.subscribe("on_before_ajax_request", this._onBeforeAjaxRequest1, this);
			var form = RightNow.Form.find('rn_QuestionSubmit', this.instanceID);
			form.on("submit", this.onValidate, this);
		}
	,
	validateForm: function(type, args){
			
			var elem = document.getElementById('rn_QuestionSubmit').elements;
			
			var a = [];
			var result = {};
			
			for(var i = 0; i < elem.length; i++)
			{
				var element = elem[i];
				var item = {};
				
				if (element.name === '' || element.name.indexOf(".") >= 0) { continue;}
				if (element.type === 'select-one') {
					item.text = element.options[element.selectedIndex].text;
				}
				
				item.group = element.dataset.group;
				item.name = element.name;
				
				if (element.type === 'radio' || element.type === 'checkbox') {
					if (element.checked) {
						item.value = element.value;
						if (result[element.name]) {
							var lastEntry = result[element.name].slice(-1)[0];
							if (lastEntry.group === item.group) {
								lastEntry.value += "," + element.value;
							} else {
								result[element.name].push(item);
							}
						}

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!