You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by eaglei22 <jc...@gmail.com> on 2013/09/09 18:13:08 UTC

How to clear autoComplete textfield in Wicket after submit?


I'm having issues clearing the input of a autoComplete Textfield.. For some
reason whenever I call target.add(reference to AutoCompleteTextField);

my input values are null...

So basically, I can clear the referenced string the input is stored in, but
everytime I call an ajaxupdate it nulls.

I tried both ajaxButton, and AjaxSubmitLink. Both get the same reactions. I
have a button to submit the input from the textField.

Code:

        <form wicket:id="autoCompleteForm">
          	<input wicket:id="autoCompleteTextField" size="20"/>
          	<button width:100px wicket:id="selectRoleBtn">Select</button>    
        </form>


private void autoCompleteForm()
{
    findRoleForm = new Form<Void>("autoCompleteForm");
    findRoleForm.setOutputMarkupId(true);
    addOrReplace(findRoleForm);
    field = new AutoCompleteTextField<String>("autoCompleteTextField",
            new PropertyModel<String>(this,"autoString"))
        {
            @Override
            protected Iterator<String> getChoices(String input)
            {
                if (Strings.isEmpty(input))
                {
                    List<String> emptyList = Collections.emptyList();
                    return emptyList.iterator();
                }

                List<String> choices = new ArrayList<String>(10);

                for (final Role role : rolesList)
                {

                    final String roles = role.getRoleName();

                    if (roles.toUpperCase().startsWith(input.toUpperCase()))
                    {
                        choices.add(roles);
                        if (choices.size() == 10)
                        {
                            break;
                        }
                    }
                }

                return choices.iterator();
            }
        };
        findRoleForm.addOrReplace(field);
        findRoleForm.addOrReplace(new AjaxSubmitLink("selectRoleBtn",
findRoleForm)
        {
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                System.out.println("here1" + autoString);
                if(rolesList  != null && autoString!= null)
                {
                    if(rolesList .size() != 0)
                    {   
                        for(int i=0; i < rolesList .size(); i++)
                        {
                            System.out.println("here2" + autoString);
                            if(rolesList
.get(i).getRoleName().equals(autoString))
                            {
                                role = rolesList.get(i);

                                roleInformation.addOrReplace(new
Label("roleNameTxt", role.getRoleName()));
                                roleInformation.addOrReplace(new
Label("roleAliasTxt", role.getRoleAlias()));
                                roleInformation.addOrReplace(new
Label("roleOwnerTxt", role.getRoleOwnerId()));
                                roleInformation.addOrReplace(new
Label("roleStatusTxt", role.getRoleAccessStatus()));
                                roleInformation.addOrReplace(new
Label("roleCategoryTxt", role.getRoleCategoryName()));
                                roleInformation.addOrReplace(new
Label("roleDescriptionTxt", role.getRoleDescription()));
                                roleInformation.addOrReplace(new
Label("roleValidityTxt", role.getRoleValidityStatus()));
                                roleInformation.addOrReplace(new
Label("roleNumUsers", ""));


                                //add adOrReplace(findRoleForm);
                                autoString = "";
                                target.add(field);
                                target.add(roleInformation);
                                currentRoleSelection = null;
                                target.add(rolesDropDownChoice);
                                break;
                            }
                        }
                    }
               }
            }
        }).add(getIndicatorAppender());
}





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-clear-autoComplete-textfield-in-Wicket-after-submit-tp4661268.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to clear autoComplete textfield in Wicket after submit?

Posted by eaglei22 <jc...@gmail.com>.
To add: The autoCompleteTextField input field clears the first time, but when
I try it again. The string: autoString will be null. So if you choose your
selection on first attempt (from the search list provided), hit select
button, it gives you the correct string and clears. But when you do it for a
second time, selected a provided value, the "autoString" will be null.. and
will not get the input value assigned to it.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-clear-autoComplete-textfield-in-Wicket-after-submit-tp4661268p4661269.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org