form.ajax inside a List of CssSel

20 views
Skip to first unread message

Rike-Benjamin Schuppner

unread,
Feb 22, 2017, 3:03:46 PM2/22/17
to Lift
Hi,

I am currently generating some list of user data form a ".users *" #> userList selector (def userList: List[CssSel]), which therefore repeats my following HTML snippet

    <div class="users">
    <form data-lift="form.ajax"><span class="user-name"></span><button>delete me</button></form>
    </div>

Naturally, the form snippet with user data and button is repeated a bunch of times. However, since the form.ajax part is (apparently) evaluated before the HTML is passed to the CSS trafo, each form has the very same id element. Is there a way to get around this? Especially because it seems to interfere with SHtml.idMemoize which then only reloads the very first form. Or maybe there is a completely new and better way to do this nowadays?

Thanks
/rike

Antonio Salazar Cardozo

unread,
Feb 22, 2017, 7:30:08 PM2/22/17
to Lift
Hmmm… Are you using `eager_eval`? Typically Lift will evaluate snippets outside-in,
so `form.ajax` should be evaluated on each of the resulting forms, rather than evaluated
once and then repeated. It may help to know more about what's in `userList`. Perhaps the
most straightforward thing to do is to post an example project.
Thanks,
Antonio

Rike-Benjamin Schuppner

unread,
Feb 23, 2017, 10:31:01 AM2/23/17
to Lift
Yes, I think eager_eval is activated. (Though I don’t know anymore what was the reason for that.) I’ll see if I can create a minimal example.

Antonio Salazar Cardozo

unread,
Feb 23, 2017, 3:29:50 PM2/23/17
to Lift
If you're using eager_eval, that'll be the culprit, as it will force the form to be evaluated once,
and then that's what will get repeated.

Rather than handle it that way, I would drop the `data-lift` from the template and attach it in
the CSS selector transforms you have in `userList` (something like `"form [data-lift]" #> form.ajax`,
though you can do what I usually do which is `"form" #> SHtml.makeFormsAjax andThen ...`.
Thanks,
Antonio

Rike-Benjamin Schuppner

unread,
Feb 24, 2017, 9:34:50 AM2/24/17
to Lift
Thanks a lot. I’ll look into how I can adapt my code to your solution.

Cheers
/rike
Reply all
Reply to author
Forward
0 new messages