fileupload and bindLocalAction together in a CssBoundLiftScreen

57 views
Skip to first unread message

GU

unread,
Jul 16, 2013, 3:55:30 AM7/16/13
to lif...@googlegroups.com
Hello, Lifters

I have a little bit of complicated css-bound-lift-screen based form, which consists of:
- file upload ( SHtml.fileupload needs defaultToAjax_?=false)
- one select depends on another select's value ( bindLocalAction needs defaultToAjax_?=true)

Is it possible to have file upload and ajaxed select together in one lift screen?

One more question is about how to use selectObj for bindLocalAction.
The form has a city select which depends on a country select's value.
I use bindLocationAction to get notified when the country select's onchange event is trigger,
But I dont know how to use selectObj(like what I do with country field) to create the city select.

I have uploaed a sample application at: https://github.com/guxg/lift_screen
The code file is MyScreen.scala


Please help me.
Thanks.
Gu

Peter Brant

unread,
Jul 16, 2013, 6:26:15 PM7/16/13
to lif...@googlegroups.com
That is a tricky one.  I'm afraid that's not supported currently.  The shortest path to supporting it would probably be to enhance Lift's Ajax glue to support FormData.  That would at least get things working in modern browsers.

Regarding your select question, you can call setOtherValue on your cities select and then replay the form by returning the result of the replayForm method.

Pete




--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

GU

unread,
Jul 16, 2013, 11:55:35 PM7/16/13
to lif...@googlegroups.com

Thanks, Peter.

Regarding the ajaxed select problem, it works now.  I use bindLocalAction to update cities select and return the result of  replayForm as the JsCmd.

Anyway, I have another problem about a custom field's value.

The form has a custom field for showing enumeration as radio inputs. 
When the cities select is updated (by replayForm), the gender's value is reset to Empty.
How to keep value of the gender radio during relayForm?

I have updated the sample application at: https://github.com/guxg/lift_screen
The code file is MyScreen.scala

Thanks.

=====

val gender = new Field {    
    type ValueType = Box[Gender.Value]
    def manifest = scala.Predef.manifest[Box[Gender.Value]]
    def name = "gender"
    def default = Empty

    import Gender._
    val options: Seq[Gender] = Gender.values.toSeq
    val radio: ChoiceHolder[Gender] = SHtml.radioElem(options, default) {
      selected =>
        {
          set(selected)
        }
    }

    override def toForm = Full(LabelStyle.toForm(radio))
    override def binding: Box[FieldBinding] = Full(FieldBinding(name, Self))
  }

=====




Peter Brant於 2013年7月17日星期三UTC+8上午6時26分15秒寫道:

GU

unread,
Jul 17, 2013, 10:41:04 AM7/17/13
to lif...@googlegroups.com

Dear Lifters and Peter,

Is it possible to only replay the cities select instead of replay the whole form?

Thanks.
GU

GU

unread,
Jul 17, 2013, 11:21:00 AM7/17/13
to lif...@googlegroups.com

Sorry for bother again. I have a tight schedule for a project and this is the first time for me to use liftweb.
==

I have a try with SetHtml instead replayForm like this:

def updateCityInfo: JsCmd = {
   city.setOtherValue(country.get.cities.all)
   //replayForm
   city.toForm.map(n => SetHtml("register_city_field",n)).openOr(Noop)
   //how to do the css binding here?
}

It works well.
But how to use the css-binding to generate the html, including labels, helpers, inputs, errors?

Thanks very much.




GU於 2013年7月17日星期三UTC+8下午10時41分04秒寫道:

Peter Brant

unread,
Jul 17, 2013, 6:33:05 PM7/17/13
to lif...@googlegroups.com
It's not currently possible to extract the CssSel for a single field.  That would be a really nice enhancement though.  

The other tricky part about partial updates is that you need to update the hidden snapshot restoring field to keep the client view in sync with the server side view.  I don't mind throwing up an example project showing how we do it if you want, but please keep in mind it's not part of official Lift for a reason (mainly because it's rather a hack and jQuery-specific).  I'm out the door shortly for a long weekend though so I wouldn't be able to look at this before Monday.

Pete




--

Peter Brant

unread,
Jul 17, 2013, 6:35:16 PM7/17/13
to lif...@googlegroups.com
It looks like you're always passing default as the current value of the field here:

 val radio: ChoiceHolder[Gender] = SHtml.radioElem(options, default) {

it should be the current value of the field (i.e. the result of calling the get method).

Pete


GU

unread,
Jul 17, 2013, 6:58:49 PM7/17/13
to lif...@googlegroups.com

Thanks. 

Peter Brant於 2013年7月18日星期四UTC+8上午6時35分16秒寫道:

GU

unread,
Jul 17, 2013, 7:10:56 PM7/17/13
to lif...@googlegroups.com

Hacking is attractive and help me deep into the internal of lift-screen.
It would be a great help with an example. Please ~~~


Currently, I use the following method to do partial updates of the cities select.
The key point is to embed the field template directly with the toForm nodeseq.
But I do nothing with the hidden snapshot, so there maybe something wrong?

city.toForm.map(n => {
  val fn = n \ "@name"
  SetHtml("register_city_field",
    <div id="register_city_field">
      <span class="label" for="{fn}">{ city.name }</span>
      { n }
    </div>)
}).openOr(Noop)


Peter, thank you vey much for helping me.



Peter Brant於 2013年7月18日星期四UTC+8上午6時33分05秒寫道:

GU

unread,
Jul 19, 2013, 5:15:30 AM7/19/13
to lif...@googlegroups.com

I use the following code to update the restoreAction to bind the latest snapshot inside the main form.

But have no idea to how to handle with the cancel and prev form?
Help please...


def replaceCityInfo: JsCmd = {
  city.setOtherValue(country.get.cities.all)

  val snapshot = createSnapshot
  val restoreAction = S.formGroup(-1)(SHtml.hidden(() =>
    snapshot.restore()) % new UnprefixedAttribute("data-lift-screen-control", Text("restoreAction"), Null)) \ "@name"
  val jsR = Run("""
            $('#%s input[data-lift-screen-control="restoreAction"]').attr('name',"%s");
            """.format(NextId.get,restoreAction))

  city.toForm.map(n => {
    val fn = n \ "@name"
    SetHtml("register_city_field",
      <div id="register_city_field">
        <span class="label" for="{fn}">{ city.name }</span>
        { n }
      </div>)
  }).openOr(Noop) & jsR

}


GU於 2013年7月18日星期四UTC+8上午7時10分56秒寫道:
Reply all
Reply to author
Forward
0 new messages