Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically add and remove components without AJAX?
    primarykey
    data
    text
    <p>I have a dynamic form that I'm writing in Wicket with a handful of forms that get duplicated with a "Click here to add more issues" type of button. I've written a very basic (I'm still new to Wicket) AJAXy listener that mostly works, but I can't figure out how to remove or even hide the items in my ListView.</p> <p>This makes me wonder, is there any way to just have some JS duplicate the form fields? Before I retooled the form with Wicket components I had the Jquery Dynamic Form Plugin duplicating the values. This worked great and was very easy to understand (an important plus). However I can't figure out how this would affect Wicket if I simply used the plugin instead of something like </p> <pre><code> //Issue box magic final MarkupContainer rowPanel = new WebMarkupContainer("issuesPanel"); rowPanel.setOutputMarkupId(true); form.add(rowPanel); ArrayList numIssues = new ArrayList(); numIssues.add(new Object()); numIssues.add(new Object()); numIssues.add(new Object()); final ListView lv = new ListView("issuesBox", numIssues) { @Override protected void populateItem(ListItem item) { int index = item.getIndex() + 1; item.add(new DropDownChoice("issues", combinedIssues)); item.add(new TextField&lt;String&gt;("note")); } }; lv.setReuseItems(true); rowPanel.add(lv); form.add(new AjaxSubmitLink("addIssue", form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { lv.getModelObject().add(new Object()); if (target != null) target.add(rowPanel); } }.setDefaultFormProcessing(false)); form.add(new AjaxSubmitLink("removeIssue", form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { //Wicket gets very angry when you remove components, so just hide it (recommended way) if (target != null) { Component lastObject = (Component)lv.get(lv.getList().size() - 1); lastObject.setVisible(false); log.debug("Components " + lv.get ); } } }.setDefaultFormProcessing(false)); </code></pre> <p>The JQuery plugin is much easier to use, but how can I tell Wicket that there are more fields than it thought there were? </p> <p>Note I'm also trying to avoid the AJAX call just to add a new issue which in the siltation I'm using the app in might become a problem.</p> <p>Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload