hudi
hudi

Reputation: 16525

How to set value with button to input text in wicket

I have input text:

        <div><label wicket:for="name">Name</label><input type="text" wicket:id="name" /></div>

Now I need to add two buttons which just add to this input text some value. How can I implements this ?

with this buttons I dont want do send form just edit value in input rext

Upvotes: 0

Views: 2584

Answers (3)

Cedric Gatay
Cedric Gatay

Reputation: 1583

This has nothing to do with Wicket, this is just plain Javascript. You can do something like this

<div>
 <label wicket:for="name">Name</label>
 <input type="text" wicket:id="name" id="markupId"/>
 <input type="button" value="Do something" onclick="javascript:editField();"/>
</div>

With the following Javascript somewhere in your page (or in loaded script files):

function editField(){
  document.getElementById("markupId").value = "My value";
}

If you use a Javascript framework like JQuery, you should bind the function to the onclick event using your framework (prevents polluting HTML with your javascript)

Upvotes: 0

Nicktar
Nicktar

Reputation: 5575

You don't have to send the whole form. You could use an AjaxButton with an onClick-method changing the model of your input field and adding the field to the AjaxRequestTarget. Anything not involving a server roundtrip at least by Ajax would be hard to do using wicket methods since wicket runs on the server. Of course you could do this by JavaScript but that wouldn't involve wicket.

Upvotes: 1

manurajhada
manurajhada

Reputation: 5380

Use <input type="button">Click Me</input>.

and at onclick event of these buttons call a javascript function which will edit the input text.

Upvotes: 1

Related Questions