Page 1 of 1

Change Repeatable Form Field Type Dropdown Values

Posted: Mon Mar 18, 2019 5:42 am
by sazbaztaz
Hi there I'd really need some help with the following issue...

I have repeatable form field type that looks like:

Code: Select all

	<field name="user_assign"
	type="repeatable"
	icon="list"
	description="Description"
	label="manage">
		<fieldset hidden="true" name="user_assign_modal" repeat="true">
			<field name="user" query="SELECT id, CONCAT(firstname, ' ', lastname)AS fullname FROM #__mxd_users WHERE owner = [USER_ID] ORDER BY firstname ASC" key_field="id" value_field="fullname" type="sql" required="false" label="Select User" description="Select user to assign.">
				<option value="">Please select...</option>
			</field>
			<field name="allocated_hours"
				label="Allocated Hours"
				size="45"
				type="text" />
		</fieldset>
	</field>
The field gets rendered in my form and is repeatable there are no issues with that. What I need to do however is change the "user" dropdown values on the CLIENT SIDE by ajax depending on the value of another dropdown selected.

Tried this approach as a test but it does not work...

Code: Select all

//options fetched from server via ajax
var newOptions = {"Option 1": "value1",
  "Option 2": "value2",
  "Option 3": "value3"
};
var el = jQuery("select#jform_user");
el.empty(); // remove old options
jQuery.each(newOptions, function(key,value) {
	el.append(jQuery("<option></option>")
	.attr("value", value).text(key));
});

jQuery('select#jform_user').trigger( "liszt:updated" );
jQuery('select#jform_user').trigger( "change" );
I assume the option values are stored somwhere in a javascript variable... Any help would be much appreciated.