Hello,
I've got a problem when using the AutoComplete widget.
----------------
Problem
----------------
I've got three fields which are all autocomplete fields. When i submit
the form I check if the three fields aren't blank and have different
values
If i deliberately enter the same value in field 1 and 3, lets say
"wordpress" it display an error message (S.error("")), which is what i
intended. The problem arises when i manually edit the field to lets
say 'wordpress2' and hit submit - the validation fails because it
didn't update the variable properly in my snippet. The weird thing is
that it updates the variable if i pick a value from the autocompletion
list it.
----------------
Information
----------------
Version: 2.0-M1
----------------
file
----------------
package scalableKvidr.snippet
import xml.{Text, NodeSeq}
import _root_.net.liftweb.util.Helpers._
import _root_.net.liftweb.mapper._
import net.liftweb.http.S._
import net.liftweb.http.SHtml._
//import scalableKvidr.lib.{MyAutoComplete => AutoComplete}
import scalableKvidr.model.{Tag}
import net.liftweb.http.{S, RequestVar}
import scala.util.regexp
import _root_.net.liftweb.widgets.autocomplete._
/**
* Created by TextMate.
* User: Mads
* Date: Jan 13, 2010
* Time: 7:52:22 PM
* To change this template use File | Settings | File Templates.
*/
class SignUp {
def pickTags(xhtml: NodeSeq) :NodeSeq = {
val myoptions: List[Pair[String,String]] = ("width","300") :: Nil
object username extends RequestVar("Mads") // will fetch from
twitter
object imagelink extends RequestVar("http://a1.twimg.com/
profile_images/446431308/IMGP0648_bigger.jpg") // will fetch from
twitter
object message extends RequestVar("Jeg har lige oprettet mig selv
i det danske twitter-indeks http://kvidr.dk under kategorierne:")
object email extends RequestVar("Email")
object joinNewsletter extends RequestVar(true)
object followKivdr extends RequestVar(true)
object tag1 extends RequestVar("")
object tag2 extends RequestVar("")
object tag3 extends RequestVar("")
var emailClass = if(joinNewsletter) "email" else "email
disabled"
def processUser() {
val emailRegxp = """([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]
{2,4})""".r // creates a regexp
var containErrors = false
// validations
if ( List(tag1.is,tag2.is,tag3.is).filter(_.length >
0).removeDuplicates.size != 3 ) {
containErrors = true
S.error("Du skal vælge 3 unikke tags")
}
if ( joinNewsletter &&
emailRegxp.findFirstMatchIn(email.is) ==
None ){
containErrors = true
S.error("Den indtastede email er ugyldig")
}
if (!containErrors) {
println("message: " + message + " email: " +
email)
S.notice("Tillykke, du er nu oprettet under
kategorierne: " +
tag1.is + ", " + tag2.is + ", " + tag3.is)
redirectTo("/tilmeld/nybruger/" + tag1.is + "/"
+ tag2.is + "/" +
tag3.is)
}
}
def autoCompleteData(current: String, limit: Int) :Seq[String] =
{
Tag.findAll(Like(Tag.tag, current+"%")).map{ tag :Tag =>
tag.tag.is}
}
bind("user", xhtml,
"twitter_username" -> Text(username),
AttrBindParam("imagelink",Text(imagelink),"src"),
"tag1" -> AutoComplete(tag1.is,autoCompleteData
(_,_), (input: String) => { tag1(input); println(tag1+","+input) }/*,
myoptions ::: List(("inputClass","'tag first-tag'"))*/),
"tag2" -> AutoComplete(tag2.is,autoCompleteData
(_,_), (input: String) => { tag2(input); println(tag2+","+input) }/*,
myoptions ::: List(("inputClass","'tag'"))*/),
"tag3" -> AutoComplete(tag3.is,autoCompleteData
(_,_), (input: String) => { tag3(input); println(tag3+","+input ) }/*,
myoptions ::: List(("inputClass", "'tag'"))*/),
"message" -> textarea(message.is, message(_)) %
("id" -> "message"),
"email" -> text(email.is, email(_)) % ("class" ->
emailClass) % ("disabled" -> (!joinNewsletter.is).toString),
"newsletter" -> checkbox(joinNewsletter.is,
joinNewsletter(_), ("class" -> "email-checkbox")),
"followkvidr" -> checkbox(followKivdr.is, followKivdr
(_), ("class" -> "follow-kvidr-checkbox")),
"submit" -> submit("Jeg er klar - tilmeld",
processUser ))
}
}
Thanks :)
Mads Hartmann Jensen
--
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.