Dyanmic Grid Control Picklist Saving

Posted by IramK on 05-Jan-2015 05:44

Hello,

I am working on a piece of jquery code that would allow me to dynamically create a picklist using the .append() function. I am able to clear a picklist at start using the .empty() function and then append to that picklist using the .append() function. Now when I click on the Rollbase save button on a form, the value from the picklist doesn't get saved because its dynamically created rather than being available from within Rollbase. Is there a way I could save this picklist selected option value and then get it back to show on load?

Note: There can be 'n' number of those grid items. Any possible solution to this?

Posted by matman on 05-Jan-2015 06:54

Hi IramK,

I think you could do this the following way.

Add a text field to your object or related grid object. This field will store the selected picklist option. Now create a JavaScript function on your page that can copy a value into the text field. Now go to the "Page" section on your Object property page. Click on the "properties" link of the page you added the JavaScript function to. In the "onSubmit" field, enter "yourFunction();".

yourFunction is the function you added to the page. This function will contain something like this:

<script>
	function yourFunction() {
		var picklistValue = rbf_getFieldValue("R114241202");
		rbf_setFieldValue("picklistStorer", picklistValue);
	}
</script>

Now you must add another function that can generate the dynamic picklist. This function must also be able to retrieve the value of the text field and select the corresponding picklist option. You could add this function call to the "onLoad" field of the page properties.

All Replies

Posted by matman on 05-Jan-2015 06:54

Hi IramK,

I think you could do this the following way.

Add a text field to your object or related grid object. This field will store the selected picklist option. Now create a JavaScript function on your page that can copy a value into the text field. Now go to the "Page" section on your Object property page. Click on the "properties" link of the page you added the JavaScript function to. In the "onSubmit" field, enter "yourFunction();".

yourFunction is the function you added to the page. This function will contain something like this:

<script>
	function yourFunction() {
		var picklistValue = rbf_getFieldValue("R114241202");
		rbf_setFieldValue("picklistStorer", picklistValue);
	}
</script>

Now you must add another function that can generate the dynamic picklist. This function must also be able to retrieve the value of the text field and select the corresponding picklist option. You could add this function call to the "onLoad" field of the page properties.

Posted by Godfrey Sorita on 05-Jan-2015 11:04

Picklist option values are not intended to be dynamic on end-users. Perhaps using a lookup field rendered as a picklist is a better solution to this requirement.

On the grid control properties, lookup fields can be configured to render as a picklist. There is also an option to enable quick create on each lookup field (See screenshot below):

When these options are enabled, it creates a grid control with a dynamic picklist value.

Regards,

Godfrey

Posted by IramK on 05-Jan-2015 11:26

Thanks. I'll try and get that working.

Posted by IramK on 06-Jan-2015 03:32

[mention:8397e63abfcb4743aa450d5d1919f4a0:e9ed411860ed4f2ba0265705b8793d05] : With regards to getting the values back from the hidden fields if there are lets say 10 records in my grid control and I would like to set my picklist values from those saved hidden field values, how can I loop through all the available list of records in the grid control so that I can set the picklist values from their respective hidden field values "Onload"?

Posted by matman on 06-Jan-2015 04:38

Hi Iram, You could loop through all your grid records and retrieve the hidden field value using the following piece of code:

function yourFunction() {
	var gridNo = 0;
	var maxRows = rbf_getMaxRowIndex2(gridNo);
	
	for(var rowIndex = 0; rowIndex < maxRows; rowIndex++) {
		var hiddenFieldValue = rbf_getGridValue2(gridNo, "hiddenField", rowIndex);
		
		
	}
}

After retrieving the value "var hiddenFieldValue" you can use JQuery to select the dynamic picklist option. Make sure to populate the picklist before selecting!

Posted by matman on 06-Jan-2015 04:46

I forgot to add something. My solution relies entirely on JavaScript and storage fields. I usually dislike this because it's client-side and not server-side. Perhaps you could check if Godfrey's solution works for you? His solution seems to me like it would be more "right" and less hacky.

Posted by IramK on 06-Jan-2015 05:36

Thanks for the answer. Yes I will look into Godfrey's solution as well.

Cheers.

This thread is closed