I actually encountered situations where I had to pass actual data as hidden field. For instance we had a SAML service that also provided a login widget as a convenient way to login the user directly into the user's realm service and that service after auth redirected the user to the originator service. But it needed service name to be passed as a hidden field :D ... I know passing data in hidden field is in many respects suboptimal but sometimes application are constrained to do so and since HTML allows passing any data via hidden field I see no reason for not do this little "shortcut" for the users in SHTML to overload the hidden to also accept the client's value. I hope you don't mind me adding that but if you do please let me know. After all SHTML functions are just helpers at the end of the day.
Br's, Marius On Apr 7, 5:40 pm, David Pollak <[email protected]> wrote: > Marius -- Thanks for giving the answer. > The reason that SHtml.hidden() takes () => Unit is that I could not think of > a use case for passing data back and I was tired of ignore => {...} in my > code. > > As a broader issue, there's nothing magic in Lift. You can see how Marius > grabbed the existing code and built a function that does exactly what you > want. We've tried to layer Lift so that it's easy to add what you need. > > Thanks, > > David > > > > On Tue, Apr 7, 2009 at 6:37 AM, marius d. <[email protected]> wrote: > > > Note the SHtml.hidden function is defined as: > > > def hidden(func: () => Any, attrs: (String, String)*): Elem = > > makeFormElement("hidden", NFuncHolder(func), attrs :_*) % ("value" -> > > "true") > > > see that it automatically puts value = true. > > > It used to accept a function like (String) => Any but I'm not sure why > > it doesn't anymore. Probably to "enforce" the usage of hidden fields > > to act as flags instead of actual data. Nonetheless I still think we > > should overload hidden function to accept the String value ..like: > > > def hidden(func: (String) => Any, attrs: (String, String)*): Elem = > > > Anyways in the mean time you can try something like: > > > def hidden(func: (String) => Any, attrs: (String, String)*): Elem = > > S.fmapFunc(SFuncHolder(func))(funcName => > > attrs.foldLeft(<input type="hidden" name={funcName}/>)(_ % _)) > > > and now your function should receive the actual value specified in the > > hidden field. Note that I didn't test the above function :D ... let me > > know if it works for you. > > > Br's, > > Marius > > > On Apr 7, 3:15 pm, wapgui <[email protected]> wrote: > > > Thanks for the reply I found the js solution this night too, but the > > > delivery of messages on google groups seems to be very slow (Now 6 > > > hours pending). > > > Now I have only left one little problem. > > > This should give me the value : "color" -> hidden(() => fp.color) % > > > ("id" -> "color"). But it's empty and the definition of hidden allows > > > only () => fp.color not fp.color = _ like on text for example. May be > > > my scala skill is not good enough to find a solution. > > > > Cheers > > > Torsten > > > > On Apr 7, 8:56 am, "marius d." <[email protected]> wrote: > > > > > On Apr 6, 10:05 pm, wapgui <[email protected]> wrote: > > > > > > Did you mean something like that ? > > > > > "color" -> hidden(() => fp.color) % ("id" -> "color") > > > > > Yes > > > > > > But how can I get the value of the "color" and how to set the value > > > > > via js if the form has no name and the name of the input is > > generated. > > > > > > <form method="post" action="/"> > > > > > <input value="true" type="hidden" > > name="F9112749168471LP" > > > > > id="color" /><br /> > > > > > Well knowing the unique node id you don't need the form's name or id. > > > > you can just say: > > > > > $("#color").attr("value", "some value") ... using JQuery > > > > > or raw JavaScript > > > > > document.getElementById("color").value = "some value"; > > > > > or using Lift's abstractions > > > > > JsCmds.SetValById("color", "some value") ... but you need to use this > > > > in the context where a JsExp/JsCmd is appropriate (JS events, return a > > > > JavaScript as a result of an Ajax call etc) > > > > > > It's all so difficult if there are no examples. But I will post my > > > > > small experience on my website to help other newbies. > > > > > No worries it is good to ask questions. > > > > > > Cheers > > > > > Torsten > > > > > > On Apr 6, 4:47 pm, "marius d." <[email protected]> wrote: > > > > > > > Well putting an id to the hidden field allows you to manipulate it > > via > > > > > > JavaScript. > > > > > > > Br's, > > > > > > Marius > > > > > > > On Apr 6, 5:01 pm, wapgui <[email protected]> wrote: > > > > > > > > Hi, > > > > > > > > is there an equivalent in lift to the hidden input filed used in > > > > > > > forms. The SHtml.hidden is only for functions not for parameters, > > the > > > > > > > value is always true. I want set the hidden input via javascript. > > > > > > > > Is there also a parameter for setting the name of the form > > itself? > > > > > > > > Here the code: > > > > > > > > object smlink extends RequestVar(Full("")) > > > > > > > > var fp = new Widget() > > > > > > > > def show(xhtml: NodeSeq): NodeSeq = { > > > > > > > val temp = > > > > > > > if (smlink.isEmpty || smlink.open_!.length == 0) "" else > > > > > > > "Received: " + smlink.open_! > > > > > > > > bind("fp", xhtml, > > > > > > > "color" -> hidden({() => fp.color}), > > > > > > > "title" -> text(fp.title, fp.title = _) % ("size" -> "10") > > % > > > > > > > ("id" -> "title"), > > > > > > > "url" -> text(fp.url, fp.url = _) % ("size" -> "56") % > > ("id" -> > > > > > > > "url"), > > > > > > > "items" -> select((1 to 9).toList.reverse.map(v => > > (v.toString, > > > > > > > v.toString)), > > > > > > > Empty, fp.items = _), > > > > > > > "submit" -> submit("Send", () => { > > > > > > > Log.info("Submitted ") > > > > > > > smlink(Full(fp.title)) > > > > > > > }), > > > > > > > "link" -> <div>{temp}</div> > > > > > > > ) > > > > > > > } > > > > > > > > generates this: > > > > > > > > <form method="post" action="/"> > > > > > > > <input name="F1142516722376UOU" type="hidden" > > value="true" /><br /> > > > > > > > <label for="title">Title</label> > > > > > > > <input size="10" name="F1142516722377UCO" type="text" > > value="" > > > > > > > id="title" /><br /> > > > > > > > <label for="url">URL</label> > > > > > > > <input size="56" name="F1142516722378IZS" type="text" > > value="" > > > > > > > id="url" /><br /> > > > > > > > <label for="items">Items</label> > > > > > > > <select name="F1142516722379K2S"><option value="9">9</ > > > > > > > option><option value="8">8</option><option > > value="7">7</option><option > > > > > > > value="6">6</option><option value="5">5</option><option > > value="4">4</ > > > > > > > option><option value="3">3</option><option > > value="2">2</option><option > > > > > > > value="1">1</option></select><br /> > > > > > > > <input name="F1142516722380W2M" type="submit" > > value="Send" /> > > > > > > > <div></div> > > > > > > > </form> > > > > > > > > Cheers > > > > > > > Torsten > > -- > Lift, the simply functional web frameworkhttp://liftweb.net > Beginning Scalahttp://www.apress.com/book/view/1430219890 > Follow me:http://twitter.com/dpp > Git some:http://github.com/dpp --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
