(from Danny's email to the WebDSL mailing list)

A common use-case for Ajax actions is responding to a change in an input component.

Example from yellowgrass.org (simplified):

define createIssue(p:Project){
   var i : Issue
   form{
     "title: "
     input(i.title)[onkeyup := action{ replace(p1,showTitles()); }]
     placeholder p1 {  }
     input(i.content)
     captcha
   }
   action showTitles(){
     someSearchFunction(i.title,p.name);
   }
}

With the current mechanism, the onkeyup action behaves like a regular form submit, which submits all the inputs of the form and performs databinding and validation. The result in this example is that the action never does what you want, which is to show similar titles, because you haven't entered the captcha text correctly.

To solve this problem and also make ajax actions more light-weight, we could add a new type of ajaxaction/ajaxfunction. These would be defined outside of pages/templates. The arguments are entirely constructed in the client. The action is the entry-point on the server (could even be used as a crude web service), and has its own access control rule type.

Example:

define createIssue(p:Project){
   var i : Issue
   form{
     "title: "
     input(i.title)[onkeyup := showTitles(i.title, p.name)]
     placeholder p1 {  }
     input(i.content)
     captcha
   }
}
ajaxfunction showTitles(title:String, projectname:String){
  replace(p1,showSimilarTitles(i.title));
}

Entering something in the input will transmit the value in the input for i.title and the value for project.name from the client directly to the action on the server. Since there is no regular page handling happening, no Issue is created, the captcha is ignored, no validation is triggered.

To simplify the initial implementation and keep the actions as light as possible, only primitive types (currently String, Int, Bool, Float) are allowed to be passed to such actions.
Also, i.title, the input which has the event, would be the only argument that changes upon subsequent calls, the other arguments are literals in the generated javascript.

Some design issues:

  • should the call look different than other action calls?
  • are the common cases covered, even with these limitations?
Submitted by Sander Vermolen on 17 March 2010 at 09:25

Log in to post comments