views:

69

answers:

1

I'm using Scripaculous' in place collection editor to present the user a with list of customers to assign to a contact dynamically. I am passing a value parameter as detailed in the documentation so when the select is generated it will auto-select the current associated customer (if there is not one already the default is provided.)

This works well except when the user clicks on the 'edit me' field a second time the original value is selected, not the customer that was selected most recently. This is because the original call to InPlaceCollectionEditor is unchanged. My question is whether there is any way to update the autoselect value without dynamically updating the entire scriptaculous call (this would mean selecting all the customers again via ajax, which is possible but not ideal.)

Here is the code:

<div id="editme">Test 1</div>
    <script type="text/javascript">

  new Ajax.InPlaceCollectionEditor(
    'editme', 
    '/usercustomer/editCustomer/id/811',
    { collection: [['192981', "Test 1"],['192893', "Test 2"],['192894', "Test 3"]  ... ],
      ajaxOptions: {method: 'get'}
      , value: 192893 } // specifying the value parameter auto selects object id 192893
   );
</script>

Is this a limitation of InPlaceCollectionEditor or is there some other way around this?

A: 

Pass a variable instead of the hardcoded number as 'value'. Set that variable to the initial or selected value right before making the call.

Gipsy King
The Ajax.InPlaceCollectionEditor call is updating the div id "editme" not the the parameters of the ajax.InPlaceCollectionEditor call, which as shown in the code above, is outside the div. As I mentioned "My question is whether there is any way to update the autoselect value without dynamically updating the entire scriptaculous call"
markb
When do you want to update the autoselect value, and from what? As I said, if you use a (possibly global) variable instead of the hardcoded value you can set it whenever you please, before you make the ajax call. If you only want to set the selected option, you would have to access the select element and set it's selectedIndex proerty.
Gipsy King