javascript - Enabling/disabling form components dynamically without server round trip -


i'm creating form in text fields should enabled if checkbox checked.

i'm new wicket, , i'm curious following:

  1. can enable/disable field without (ajax) round-trip server using existing wicket classes? i.e. possible add behaviors fields causes rendered html include javascript enables/disables fields?

  2. if answer above question no: "legal" me add required javascript code myself in markup? or run risk of messing form submission not recognized wicket?

i'm new wicket , i'm not sure best practice here. perhaps wicket-way of doing involves ajax round-trip?

can enable/disable field without (ajax) round-trip server using existing wicket classes? i.e. possible add behaviors fields causes rendered html include javascript enables/disables fields?

yes, can without server round trip. no, not class provided wicket, have create yourself. here's behavior can add component. if component behavior clicked, target component passed in constructor disabled via javascript:

public class disableformcomponentbehavior extends behavior {  private component sourcecomponent;  private formcomponent targetcomponent;  public disableformcomponentbehavior(formcomponent targetcomponent) {     targetcomponent.setoutputmarkupid(true);     this.targetcomponent = targetcomponent; }  public void bind(component component) {     super.bind(component);     component.setoutputmarkupid(true);     this.sourcecomponent = component; }  @override public void renderhead(component component, iheaderresponse response) {     super.renderhead(component, response);     response.render(javascriptheaderitem             .forreference(jqueryresourcereference.get()));     response.render(ondomreadyheaderitem.forscript(string             .format("$('#%s').click(function(){$('#%s').prop('disabled', true);});",                     component.getmarkupid(), targetcomponent.getmarkupid()))); }  } 

if answer above question no: "legal" me add required javascript code myself in markup? or run risk of messing form submission not recognized wicket?

well, answer above question not "no", still legal add own javascript wicket html files. have define ids of components in html then, however. solution behaviors better, though, because more reusable.


Comments