grails, jquery chosen multiselection with g:select -


i'm using jquery chosen plugin multiselect in conjunction grails <g:select>. should selector multiple users defined in domain class via has many = [users: user]. works in cases pretty if example 3 users selected , want delete one, nothing happens. if delete 2 updates correctly. if nothing selected can add users 1 one , works.

that code in gsp:

<g:select id="pickusers" name="users" from="${usermanagement.user.list()}" multiple="true" optionkey="id" value="${projectinstance?.users*.id}" class="many-to-many"/> <script type="text/javascript">     $('#pickusers').chosen({width: "25%",                             no_results_text: "keine ergebnisse für",                             placeholder_text_multiple: "mitarbeiter suchen..."})     $('#pickusers').trigger("chosen:updated")     $('#pickusers').on('change', function() {         var currentvalues = $('#pickusers').chosen().val();         if (currentvalues == null) {             $("#pickusers").prepend("<option value='' selected='selected'></option>");         }     }); </script> 

developer tools:

_method:put version:8 users:3 users:2 _action_update:aktualisieren 

this showing right selection apparently not updating it, still shows 3 users. in grails used has many , didn't change anything.

i logged incoming users in controllers update method:

all 3 users set: users: [leader, test, me] delete test user in view: users: [leader, me, leader, test]

like mentioned happens if delete one user, if delete 2 works

edit: potential "fix" in controller:

@transactional     def update(project projectinstance) {         if (projectinstance == null) {             notfound()             return         }          //get users jquery users-picker in view         def userspicker = params.users          //clear users set of incoming instance         if(projectinstance.users !=  null){             projectinstance.users.clear()         }          //add users picker in view set         (user in userspicker){              def tempuser = user.get(user)             projectinstance.users.add(tempuser)         }          if (projectinstance.haserrors()) {             respond projectinstance.errors, view:'edit'             return         }          projectinstance.save flush:true          request.withformat {             form multipartform {                 flash.message = message(code: 'default.updated.message', args: [                     message(code: 'project.label', default: 'project'),                     projectinstance.id                 ])                 redirect projectinstance             }             '*'{ respond projectinstance, [status: ok] }         }     } 

the above mentioned logs directly incoming instance in update method. need clear users set , bind users currentvalues (javascript in view) instance.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -