简体   繁体   中英

Submitting form populated by javascript results in empty values in Wicket

What I'm trying to do is make cross select with two multiselects. And when I'm clicking a button a simple javascript would transfer an value from one to another. That is working pretty good, but when I'm trying to submit my whole form, all I'm getting is empty list. Here's code for my components.

   ListMultipleChoice<String> valueControl = new ListMultipleChoice<>("customValue",
                new DocumentModel(owner, property)/*my own model for setting properties*/,optionsList,
                new DocumentRenderer(options));
        valueControl.setRequired(property.isRequired());
        valueControl.setLabel(Model.of(property.getCaption()));
        valueControl.setOutputMarkupId(true);
        valueControl.setMarkupId("select-to");
        ListMultipleChoice<String> multiSelect = new ListMultipleChoice<>("options",new Model(), optionsList,
                new DocumentRenderer(options)); //this is my own renderer
        add(multiSelect);
        add(valueControl);

And here's my markup code.

<html xmlns:wicket="http://wicket.apache.org/">
<wicket:extend>
    <div>
        <select wicket:id="options" id="select-from" multiple
            class="form-control" data-placeholder="Nothing selected">
            <option>Select me</option>
        </select>
        <button type="button" id="btn-add">             
        </button>
        <button type="button" id="btn-remove">              
        </button>
        <select wicket:id="customValue" class="form-control" multiple id="select-to"
            data-placeholder="Nothing selected">
            <option>Select me</option>          
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#btn-add').click(function(){
            $('#select-from option:selected').each( function() {
                    $('#select-to').append("<option value='"+$(this).val()+"' selected='selected'>"+$(this).text()+"</option>");
                $(this).remove();
            });
        });
        $('#btn-remove').click(function(){
            $('#select-to option:selected').each( function() {
                $('#select-from').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
                $(this).remove();
            });
        });
        });
    });
    </script>
</wicket:extend>
</html>

Sorry if I missed something in the process. Thank you all in advance.

So you're reinventing org.apache.wicket.extensions.markup.html.form.palette.Palette ? Why?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM