[Ur] An initial wild guess attempting to wrap a Bootstrap DatePicker for Ur/Web

Ziv Scully ziv at mit.edu
Sun Aug 2 20:53:54 EDT 2015


The Ur/Web manual section on IDs (http://www.impredicative.com/ur/manual.pdf,
section 8.6.2) specifies that [id] is an abstract type, with the only way
to generate them being [fresh : transaction id]. It also makes clear that
there's no way to force the ID to be something in particular.

The pattern that Logitext uses is to generate a unique ID and both set a
node's ID with it and pass it to a JavaScript function via the FFI. This
seems like exactly the way to do what you need. For your case, it would
look something like this:

datepicker : transaction xml =
    nid <- fresh;
    return <xml>
      <div id={nid}/>
      <active code={annotateDatepicker nid; return <xml/>}/>
    </xml>

where [annotateDatepicker : id -> transaction unit] is an JavaScript FFI
function that takes an ID and calls the function from the JavaScript
library using that ID. In this case, that would be

function annotateDatepicker(nid) {
    $('#' + nid + ' div').datepicker({})
}

or something similar (not an expert on this library). It's possible you
could put the [annotateDatepicker] call outside the XML right after the
[nid <- fresh;], but I don't know if it would work.

On Sun, Aug 2, 2015 at 2:52 PM, Timothy Beyer <beyert at fastmail.net> wrote:

> At Sun, 2 Aug 2015 01:06:48 -0300,
> Stefan Scott Alexander wrote:
> > but the compiler gives errors complaining about this id in this tag.
> >
> > This datepicker library uses an id tag in the <div> enclosing the
> <input> tag. Is there a way
> > to set an id tag for a <div> in Ur/Web?
>
> Yes, it is very common to set an id attribute for a div element, especially
> when using jQuery.
>
> A common AJAX idiom in Javascript is to set id or class attributes for
> various
> elements, then send targeted HTML to those elements at runtime, based on
> user
> input.
>
> Regards,
> Tim
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150802/b45857ca/attachment.html>


More information about the Ur mailing list