How to Auto Select a specific element with ScriptAculoUs InplaceCollectionEditor when there is a Label?

48 views Asked by At

I am using Scriptaculous InPlaceCollectionEditor which enables to select in place and select one option per default. My problem is that when i try to select an option per default when there is a label, it does not select that option. In the example Below, I would like to Select Mysql by default but it is not working. When i Click on the result, it shows Php as selected by default instead of Mysql. Here is a Jsfiddle

<div id="maxime">Mysql</div> (should autoselect "Mysql")
<script>
 new Ajax.InPlaceCollectionEditor(      'maxime',      '_ajax_inplaceeditor_result.html',      {         okText: 'Ok',         cancelText: 'Cancel',         collection: [['1', 'Php'], ['2', 'Mysql'], ['3', 'Javascript'], ['4', 'C++']]      }   );
</script>

How to make this select Mysql by default without moving the position of Mysql ?

1

There are 1 answers

0
John Max On

You have to add the value to it. The value must have by default the one you would like to select. However even though it selects it by default when you do an update, it does not keep the selection. I guess that is a weakness of Scriptaculous and prototype js. So you will have to do some twisting in your programming language.

<script>
 new Ajax.InPlaceCollectionEditor(      'maxime',      '_ajax_inplaceeditor_result.html',      
 {         
 okText: 'Ok',         
 cancelText: 'Cancel',         
 collection: [['1', 'Php'], ['2', 'Mysql'], ['3', 'Javascript'], ['4', 'C++']],
 value: 2,
 ajaxOptions: {method: 'post'} //override so we can use a static for the result

 }   );
</script>